2016-02-05 61 views
0

我想連接到Quickbooks在線。我已經嘗試了幾個軟件包,包括PHPSample,v3 SDK中的示例代碼以及用於時間記帳的java示例。我最終都會遇到類似的問題。PHPSample OAuth連接QBO 401

我能夠連接到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

401響應HTTP意味着您未經授權。如果你連接到他們的沙箱,搜索他們的文檔中的一些特殊的用戶密鑰和令牌(它隱藏在他們「令人難以置信的」文檔中的某處)。實際上,我還必須在實現過程中猜測一些參數(正如他們的手冊中指出的那樣)。我的哀悼,QBO在這個流氓中非常痛苦。 –

+0

@Nordenheim感謝您的吊。。 – user3731598

回答

0

請參閱沙箱鍵和基本的URL,你需要使用這裏 - 請 refer- 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」按鈕來使用相同令牌的相同領域時,他們也會發生。 另一個原因是,管理員手動斷開realm/company手動使令牌失效。 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

+0

我不遵循你所說的話。據我所知,我發佈的代碼確實表明了這些鏈接表明我應該這樣做,並且我沒有在您發佈的鏈接中引用錯誤。你能更明確嗎? – user3731598

+0

所以,如果你已經使用開發應用程序密鑰/令牌和沙箱網址,那麼你的oauth應該可以正常工作。編輯我的ans以上 –

+0

感謝您的更新。我能夠連接,斷開連接並重新連接。我的問題是通過查詢拉取數據。請注意,我在連接時收到的領域ID與QBO中的應用程序ID不匹配。應該是? – user3731598