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 驱动学习 环境部署中的问题
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题