duanshan3331 2017-04-12 06:35
浏览 44
已采纳

Quickbooks Online API中的ApplicationAuthenticationFailed错误

When I run the Quickbooks Online API using 'Postman', it works fine. Postman automatically generates the nonce and oauth_signature value. But when I run the API using PHP, i got stuck with the following error.

message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401 SignatureBaseString: POST&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F193514525%2Faccount&oauth_consumer_key%3DqyprdH7kq5iG34sV2fSaj9tKC1KzXG%26oauth_nonce%3DFWXxbP%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1491976910%26oauth_token%3DqyprdDXeKDQonYAz8O0OSnyewIsg34HjxZyH0X4Dk5dNE5LC%26oauth_version%3D1.0

I think it may be related to generating signature value. I have used PHP '$oauth->generateSignature()' function to generate the signature. It generates the value. But the authorization error still occurs. Please help me to solve the issue.

Here I am providing the codes that I am used.

$ar =   array(
'authorization: OAuth oauth_consumer_key="'.OAUTH_CONSUMER_KEY.'",oauth_token="'.ACCESS_TOKEN_SECRET.'",oauth_signature_method="HMAC-SHA1",oauth_timestamp="'.$time.'",oauth_nonce="'.$randomvalue.'",oauth_version="1.0",oauth_signature="'.$signaturevalue.'"',
"cache-control: no-cache",
"content-type: application/json",
"Accept: application/json"

);

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://sandbox- quickbooks.api.intuit.com/v3/company/{{companyid}}/account",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{
  \"AccountType\": \"Accounts Receivable\",
  \"Name\": \"MyJobs\"
}",
CURLOPT_HTTPHEADER =>  $ar,
));
$response = curl_exec($curl);

This is the code I used for creating an account. I used following code to generate signature.

    $oauth = new OAuth(OAUTH_CONSUMER_KEY,OAUTH_CONSUMER_SECRET);
    $signature  =   $oauth->generateSignature('POST','https://sandbox-quickbooks.api.intuit.com/v3',$params);

In this case $params array defined as follows

     $params = array(
        'oauth_consumer_key' => OAUTH_CONSUMER_KEY,
        'oauth_nonce' => $randomvalue,
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_timestamp' => $time,
        'oauth_version' => '1.0',
        'oauth_token' => ACCESS_TOKEN
    );
  • 写回答

1条回答 默认 最新

  • dtbi27903 2017-04-12 14:31
    关注

    You should use a library that handles all of this stuff for you -- there are lots of issues in your code. Here's a library that handles all of this for you:

    Follow the quick-start on that page.

    Specific issues I can see with your code:

    You can't have a constant access token. It changes every 5 to 6 months, and thus is not a constant:

    oauth_token="'.ACCESS_TOKEN_SECRET.'"

    This URL has two issues:

    • It has a space in it
    • The company ID is an integer and here it looks like you put a placeholder instead

    CURLOPT_URL => "https://sandbox- quickbooks.api.intuit.com/v3/company/{{companyid}}/account",

    This URL is incorrect -- you're signing a different URL than you're POSTing to:

    $signature = $oauth->generateSignature('POST','https://sandbox-quickbooks.api.intuit.com/v3',$params);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?