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 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果