Quickbooks使用Signpost在线过滤返回401错误 [英] Quickbooks Online filtering with Signpost returns 401 error

查看:130
本文介绍了Quickbooks使用Signpost在线过滤返回401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was able to get Signpost work with QuickBooks Online using HttpPost. However when I tried querying with filters, I got 401 error every time. After contacting support, I was informed that this is a known bug. They pointed me to an example in C#. I am using Signpost oauth library in Java. The C# example doesn't make sense to me since I don't have those functions available in Signpost. Also I don't understand what exactly I need to do.

一个侧面说明:对于这种内容类型,我必须使用HttpClient:"application/x-www-form-urlencoded".这是来自路标的限制.

One side note: I had to use HttpClient for this content type: "application/x-www-form-urlencoded". This is the limitation that comes from Signpost.

未经授权的OAuth令牌:signature_invalid401SERVER

Unauthorized OAuth Token: signature_invalid401SERVER

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

The C# workaround example: 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);

推荐答案

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

AcctNum is not a valid filter for QBO Account entity.

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

您可以使用名称"属性作为过滤器.

You can use 'Name' attribute as filter.

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/account/v2/188712345

Content-Type:应用程序/x-www-form-urlencoded

Content-Type: application/x-www-form-urlencoded

将数据发布到终点:Filter =名称:EQUALS:BankCharges

post data to end point: Filter= Name :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";
    }

}

谢谢

这篇关于Quickbooks使用Signpost在线过滤返回401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆