2013-04-05 56 views
4

我正在使用QB桌面版。並且我想爲我的QuickBooks桌面版更新/重新生成'訪問令牌'/'訪問令牌保密',因爲它們將在180天內過期,並且必須在令牌到期後的30天內進行續訂。 我試圖與下面的代碼,但它不工作一樣,給人誤差,因紐特人快速書籤令牌更新和到期

<RestResponse xmlns="http://www.intuit.com/sb/cdm/v2"><Error RequestId="14aa97c48321489db48254e4bdb25d00"><RequestName>ErrorRequest</RequestName><ProcessedTime>2013-04-05T11:43:08+00:00</ProcessedTime><ErrorCode>401</ErrorCode><ErrorDesc>Invalid security token</ErrorDesc></Error></RestResponse> 

沒有爲令牌generatetion沒有任何記錄的請求/響應。

string myRealmId = "000000000000000"; 
     string myAccessToken = "0000000000000000000000000000000000000"; 
     string myAccessTokenSecret = "00000000000000000000000000000000000"; 

     string myAppToken = "00000000000000000000000000000000000"; 
     string myConsumerKey ="00000000000000000000000000000000000"; 
     string myConsumerSecret ="00000000000000000000000000000000000"; 

     OAuthConsumerContext consumerContext = new OAuthConsumerContext 
     { 
      ConsumerKey =myConsumerKey, 
      SignatureMethod = SignatureMethod.HmacSha1, 
      ConsumerSecret = myConsumerSecret 
     }; 

     OAuthSession oSession = new OAuthSession(consumerContext, "https://oauth.intuit.com/oauth/v1/get_request_token", 
         "https://workplace.intuit.com/Connect/Begin", 
         "https://oauth.intuit.com/oauth/v1/get_access_token"); 

     oSession.ConsumerContext.UseHeaderForOAuthParameters = true; 

     oSession.AccessToken = new TokenBase 
     { 
      Realm = myRealmId, 
      Token = myAccessToken, 
      ConsumerKey = myConsumerKey, 
      TokenSecret = myAccessTokenSecret 
     }; 

     var body = "<AdvancedReportQuery xmlns=\"http://www.intuit.com/sb/cdm/v2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.intuit.com/sb/cdm/v2 ..//RestDataFilter.xsd\"><BalanceSheetStd><OfferingId>ipp</OfferingId><EndTransactionDate>2012-06-01</EndTransactionDate></BalanceSheetStd></AdvancedReportQuery>"; 

     IConsumerRequest conReq = oSession.Request(); 
     conReq = conReq.Post().WithRawContentType("text/xml").WithRawContent(System.Text.Encoding.ASCII.GetBytes(body)); 
     conReq = conReq.ForUrl("https://services.intuit.com/sb/advancedreport/v2/508053445"); 
     try 
     { 
      conReq = conReq.SignWithToken(); 
     } 
     catch (Exception ex) {} 

     string serviceResponse = conReq.ReadBody(); 

     } 
     catch (Exception Err) {} 

    } 

感謝,

Reshma D.

回答

3

需要調用內令牌期滿前30日內重新連接API。看起來你的代幣已經過期了,所以你需要再次通過Oauth流程。

http://docs.developer.intuit.com/0025_Intuit_Anywhere/0060_Reference/3002_Reconnect_API

使用DevDefined和的devkit的C#示例:

https://gist.github.com/IntuitDeveloperRelations/5338762

+0

感謝您的回覆。您可以幫助我們通過數據服務調用此API。就像我們調用數據服務方法,例如,Intuit.Ipp.Data.Qbd.Customer qbdCustomer = dataServices.FindById (qbdCustomer1);感謝您的回覆。你能幫我們通過數據服務來調用這個API嗎?例如,我們稱數據服務方法爲 Intuit.Ipp.Data.Qbd.Customer qbdCustomer = dataServices.FindById (qbdCustomer1); 我們無法確定哪個Intuit Quickbooks對象可以幫助我們實現。提前感謝,Reshma D. – Reshma 2013-04-08 12:37:19

+0

此調用在DevKit中不可用。我已經通過一個如何使用DevDefined來調用API的例子更新了上面的答案。 – 2013-04-08 17:41:29

+0

謝謝彼得。我會嘗試給予參考。 – Reshma 2013-04-09 09:12:36

2

我找到一種方式,你可以在每次啓動應用程序時可以隨時訪問相同的公司。這花了我一些時間來弄清楚。但是我在節點js中做了這個;這個概念仍然適用於任何編程語言。

'use strict'; 

var request = require('request'); 
var qs = require('querystring'); 
var config = require('./environment'); 
var QuickBooks = require('node-quickbooks'); 

var postBody = { 
    url: QuickBooks.REQUEST_TOKEN_URL, 
    oauth: { 
    // This callback url is just a placeholder so QuickBooks doesn't get upset 
    callback: "http://localhost:9000/oauth/quickbooks/callback", 
    consumer_key: config.quickbooks.consumerKey, 
    consumer_secret: config.quickbooks.consumerSecret 
    } 
} 
request.post(postBody, function (e, r, data) { 
    var requestToken = qs.parse(data) 

    var postBody = { 
    url: QuickBooks.ACCESS_TOKEN_URL, 
    oauth: { 
     consumer_key: config.quickbooks.consumerKey, 
     consumer_secret: config.quickbooks.consumerSecret, 
     token:   requestToken.oauth_token, 
     token_secret: requestToken.oauth_token_secret, 
     verifier:  config.quickbooks.companyId, // This part is key 
     realmId:   config.quickbooks.companyId 
    } 
    } 
    request.post(postBody, function (e, r, data) { 
    var accessToken = qs.parse(data) 

    GLOBAL.qbo = new QuickBooks(config.quickbooks.consumerKey, 
          config.quickbooks.consumerSecret, 
          accessToken.oauth_token, 
          accessToken.oauth_token_secret, 
          config.quickbooks.companyId, 
          true); 
    console.log('Quickbooks Integration Complete'); 
    }) 
})