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>

令牌生成没有任何记录的请求/响应。

 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) {}

    }

谢谢,

瑞诗玛 D.

4

2 回答 2

3

您需要在令牌到期前 30 天内调用 Reconnect API。您的令牌似乎已经过期,因此您需要再次通过 Oauth 流程。

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

使用 DevDefined 和 DevKit 的 C# 示例:

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

于 2013-04-05T12:58:22.627 回答
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');
  })
})
于 2014-12-21T03:00:18.057 回答