我正在使用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>
令牌生成没有任何已记录的请求/响应。
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。
答案 0 :(得分:3)
您需要在令牌过期前30天内调用Reconnect API。看起来您的令牌已经过期,因此您需要再次通过Oauth流程。
http://docs.developer.intuit.com/0025_Intuit_Anywhere/0060_Reference/3002_Reconnect_API
使用DevDefined和DevKit的C#示例:
答案 1 :(得分: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');
})
})