PHPSample OAuth连接QBO 401

时间:2016-02-05 15:18:44

标签: php oauth intuit-partner-platform

我正在尝试在线连接到Quickbooks。我尝试了几个包,包括PHPSample,v3 SDK中的示例代码和时间记帐的java示例。我最终遇到了类似的问题。

我能够连接到Quickbooks,并检索realmId,oauth令牌和oauth秘密。

在这种状态下,我能够成功断开连接。

当我随后连接并尝试查询数据时(例如,所有帐户),我收到401错误。

这是返回信息(删除了我的密钥)

ERROR: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a  redirect)
Response: 401 - message=ApplicationAuthenticationFailed;
               errorCode=003200;
              statusCode=401
              SignatureBaseString: POST
                                   &https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F<REALM_ID>%2Fquery&minorversion%3D3%26oauth_consumer_key%3D<CONSUMER_KEY%26oauth_nonce%3D2172856b0bd6c51a491.36540409%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1454423404%26oauth_token%3D<OAUTH_TOKEN>%26oauth_version%3D1.0

array(6) {
  ["sbs"]=> string(369) "POST&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F<REALM_ID>%2Fquery&minorversion%3D3%26oauth_consumer_key%3DI360v9TvxGoU7UoBYesJFUiRAkVQ8OQfV4Cbl2oN%26oauth_nonce%3D2172856b0bd6c51a491.36540409%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1454423404%26oauth_token%3DqyprdWBRfbyvECJdjDA98qR6G9oPvReu65EuFtFomxS5UPXP%26oauth_version%3D1.0"
  ["headers_sent"]=> string(532) "POST /v3/company/<REALM_ID>/query?minorversion=3 HTTP/1.1 host: sandbox-quickbooks.api.intuit.com user-agent: V3PHPSDK2.2.0 accept: */* connection: close content-type: application/text Authorization: OAuth oauth_consumer_key="<CONSUMER_KEY>",oauth_signature_method="HMAC-SHA1",oauth_nonce="2172856b0bd6c51a491.36540409",oauth_timestamp="1454423404",oauth_version="1.0",oauth_token="<OAUTH_TOKEN>",oauth_signature="<ALPHA_NUM_STRING>" Content-Length: 53"
  ["headers_recv"]=> string(147) "HTTP/1.1 401 Unauthorized Server: nginx/1.8.0 Date: Tue, 02 Feb 2016 14:29:35 GMT Content-Type: text/xml Content-Length: 797 Connection: close"
  ["body_sent"]=> string(53) "select * from Account startPosition 1 maxResults 1000"
  ["body_recv"]=> string(797) " message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401 SignatureBaseString: POST&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F<REALM_ID>%2Fquery&minorversion%3D3%26oauth_consumer_key%3D<CONSUMER_KEY>%26oauth_nonce%3D2172856b0bd6c51a491.36540409%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1454423404%26oauth_token%3D<OAUTH_TOKEN>%26oauth_version%3D1.0 "
  ["info"]=> string(1280) "Adding handle: conn: 0x3a3c70 Adding handle: send: 0 Adding handle: recv: 0 Curl_addHandleToPipeline: length: 1 - Conn 5 (0x3a3c70) send_pipe: 1, recv_pipe: 0 About to connect() to sandbox-quickbooks.api.intuit.com port 443 (#5) Trying 12.149.173.155... Connected to sandbox-quickbooks.api.intuit.com (12.149.173.155) port 443 (#5) SSLv3, TLS handshake, Client hello (1): SSLv3, TLS handshake, Server hello (2): SSLv3, TLS handshake, CERT (11): SSLv3, TLS handshake, Server finished (14): SSLv3, TLS handshake, Client key exchange (16): SSLv3, TLS change cipher, Client hello (1): SSLv3, TLS handshake, Finished (20): SSLv3, TLS change cipher, Client hello (1): SSLv3, TLS handshake, Finished (20): SSL connection using AES256-SHA256 Server certificate: subject: C=US; ST=California; L=San Diego; O=INTUIT INC.; OU=Tech Ops; CN=*.api.intuit.com start date: 2015-11-23 00:00:00 GMT expire date: 2016-11-23 23:59:59 GMT issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4 SSL certificate verify result: self signed certificate in certificate chain (19), continuing anyway. upload completely sent off: 53 out of 53 bytes Server nginx/1.8.0 is not blacklisted Closing connection 5 SSLv3, TLS alert, Client hello (1): " }

ERROR MESSAGE: message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401 SignatureBaseString: POST&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F<REALM_ID>%2Fquery&minorversion%3D3%26oauth_consumer_key%3D<CONSUMER_KEY>%26oauth_nonce%3D2172856b0bd6c51a491.36540409%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1454423404%26oauth_token%3D<OAUTH_TOKEN>%26oauth_version%3D1.0

Note that
  <CONSUMER_KEY> matches what is listed in the App page on intuit under OAuth Consumer Key
  <OAUTH_TOKEN> matches what is returned from connect to quickbooks as the oauth token
  <REALM_ID> matches what is returned from connect to quickbooks as the realm id
  <ALPHA_NUM_STRING> is a string of alpha numeric characters (which look like a key string) that I do not recognize as coming from somewhere else.

我确信我做错了一些事,但我看不出来。 任何建议都将不胜感激。

提前致谢。

1 个答案:

答案 0 :(得分:0)

请在此处查看您需要使用的沙箱密钥和基本网址 - 请参考 - https://developer.intuit.com/v2/blog/2014/10/20/changes-to-ipp-app-tokens https://developer.intuit.com/blog/2014/10/24/intuit-developer-now-offers-quickbooks-sandboxes 编辑: 因此,如果您使用了开发应用程序密钥/令牌和沙箱网址,那么您的oauth应该可以正常工作。 401是令牌过期/无效错误,并且可能在以下情况下发生 - 当主管理员以外的用户尝试登录域或者使用错误的电子邮件ID登录时,会发生401错误。 如果在QBO公司中删除了主管理员,则当其他某个用户或主管理员尝试使用相同的令牌再次使用“连接到Quickbooks”按钮时,也会发生这种情况。 另一个原因是管理员手动断开领域/公司,这会使令牌无效。 401在我们结束时发生中断时也会发生。

最明显的原因是令牌到期180天。 除了我们最终的服务问题还可以断开令牌/无效令牌,并在您的最后给出401错误。

重新生成令牌 - 如果180天未结束且剩余天数为令牌到期时间> 30天/ 180天结束,则使用“连接到Quickbooks”按钮将其通过电子邮件发送给“断开连接并重新连接”。 如果180天将结束并且令牌到期的剩余天数在30天内,那么您的系统需要使用重新连接apis来续订现有令牌。 https://developer.intuit.com/v2/docs/0050_quickbooks_api/0020_authentication_and_authorization/oauth_management_api