Quickbooks使用Signpost进行在线过滤会返回401错误

时间:2013-08-14 05:05:35

标签: quickbooks intuit-partner-platform intuit quickbooks-online signpost

我能够使用HttpPost使用QuickBooks Online获得Signpost。但是,当我尝试使用过滤器查询时,每次都会出现401错误。联系支持后,我被告知这是一个已知的错误。他们向我指出了C#中的一个例子。我在Java中使用Signpost oauth库。 C#示例对我没有意义,因为我没有在Signpost中提供这些功能。我也不明白我到底需要做什么。

一方面注意:我必须使用HttpClient作为此内容类型:“application / x-www-form-urlencoded”。这是来自Signpost的限制。

未经授权的OAuth令牌:signature_invalid401SERVER

C#解决方法示例: https://gist.github.com/IntuitDeveloperRelations/6024616

/* filtering fails with 401 error */
    HttpClient client = new DefaultHttpClient();
    HttpPost requestHp = new HttpPost("https://qbo.intuit.com/qbo28/resource/accounts/v2/670436015");
    requestHp.addHeader("Content-Type", "application/x-www-form-urlencoded");
    BasicHttpEntity  filter = new BasicHttpEntity();
    filter.setContent(new StringInputStream("Filter=Name :EQUALS: Continuing"));
    requestHp.setEntity(filter);
    CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(getOauthConsumerKey(), getOauthConsumerSecret());
    consumer.setTokenWithSecret(getOauthAccessToken(),getOauthAccessTokenSecret());
    consumer.sign(requestHp);

    HttpResponse response = client.execute(requestHp);

1 个答案:

答案 0 :(得分:1)

AcctNum不是QBO帐户实体的有效过滤器。

参考 - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/account#Attributes_Supporting_Filtering_and_Sorting

您可以使用“名称”属性作为过滤器。

PFB代码段

使用java devkit

public List<QBAccount> testGetAll() {
    QBAccountQuery accountQuery = new QBAccountQuery(context);
    accountQuery.setName("BankCharges");

    final List<QBAccount> entityList = new ArrayList<QBAccount>();
    try {
        QBAccountService service = QBServiceFactory.getService(context, QBAccountService.class);
            List<QBAccount> qbAccountList = service.getAccounts(context, accountQuery);
            for (QBAccount each : qbAccountList) {
                entityList.add(each);
            }
    } catch (QBInvalidContextException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return entityList;
}

端点 - https://qbo.intuit.com/qbo1/resource/accounts/v2/188712345

内容类型:application / x-www-form-urlencoded

将数据发布到终点:过滤器=名称:EQUALS:BankCharges

使用路标

public class PocApiCall {

    static String accesstoken = "";
    static String accessstokensecret = "";
    static String appToken = "";
    static String oauth_consumer_key = "";
    static String oauth_consumer_secret = "";
    static String realmID = "";
    static String dataSource = "";
    static String url = "";

    PocApiCall() {
        setupQBO();
    }

    public static void main(String args[]) {
        PocApiCall apiCall = new PocApiCall();
        apiCall.testLikeDevkit();
    }

    private void testLikeDevkit() {

        HttpClient client = new DefaultHttpClient();
        HttpPost requestHp = new HttpPost(url);
        requestHp.addHeader("Content-Type", "application/x-www-form-urlencoded");

        BasicHttpEntity filter = new BasicHttpEntity();

        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            nameValuePairs.add(new BasicNameValuePair("Filter", "Name :EQUALS: BankCharges"));
            requestHp.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

            CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(oauth_consumer_key, oauth_consumer_secret);
            consumer.setTokenWithSecret(accesstoken, accessstokensecret);
            consumer.sign(requestHp);

            debugRequestValues(requestHp);

            HttpResponse execute = client.execute(requestHp);

            System.out.println(new BufferedReader(new InputStreamReader(execute.getEntity().getContent())).readLine());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (OAuthMessageSignerException e) {
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {   
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void debugRequestValues(HttpPost requestHp) throws IOException {
        System.out.println("Method - " + requestHp.getRequestLine().getMethod());
        System.out.println("URI - " + requestHp.getRequestLine().getUri());
        Header[] allHeaders = requestHp.getAllHeaders();
        for(Header h : allHeaders){
            System.out.println("Name - " + h.getName() + " Value - " + h.getValue());
        }

        if(requestHp.getEntity() != null){
        System.out.println(new BufferedReader(new InputStreamReader(requestHp.getEntity().getContent())).readLine());
        }
    }

    private static void setupQBO() {
        System.out.println("QBO token setup");
        accesstoken = "your tokens";
        accessstokensecret = "your tokens";
        appToken = "your tokens";
        oauth_consumer_key = "your tokens";
        oauth_consumer_secret = "your tokens";
        realmID = "688779980";
        dataSource = "QBO";
        url = "https://qbo.intuit.com/qbo1/resource/accounts/v2/123459980";
    }

}

由于