【问题标题】:Quickbooks Online filtering with Signpost returns 401 error带有 Signpost 的 Quickbooks Online 过滤返回 401 错误
【发布时间】:2013-08-15 22:13:03
【问题描述】:

我能够使用 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);

【问题讨论】:

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


    【解决方案1】:

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

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

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

    PFB代码sn-p

    使用 java 开发工具包

    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

    将数据发布到端点: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";
        }
    
    }
    

    谢谢

    【讨论】:

    • 谢谢,但这不是问题。我只是更改为使用名称,但仍然出现 401 错误。 filter.setContent(new StringInputStream("Filter=Name :EQUALS: Continuing")); intuit.com/sb/cdm/baseexceptionmodel/… OAuth Token: signature_invalid401SERVER
    • 在设置实体(过滤器)时,您应该使用 UrlEncodedFormEntity。我在我的帖子中添加了完整的工作代码 sn-p。它对我来说很好。如果有帮助,请告诉我。谢谢
    • 很高兴知道它有帮助:) 请接受答案。谢谢
    • Manas,你能看看我的另一个帖子吗?似乎 VendorCredit 需要 ItemId,这似乎很奇怪,因为它过去对我们有用。我们的客户不使用 ItemId。有解决方法吗?谢谢。 stackoverflow.com/questions/18748148/…
    • Hii Manas,在试用版上使用 API 创建客户有什么限制吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 2019-12-19
    • 2011-12-12
    • 2011-03-13
    • 1970-01-01
    相关资源
    最近更新 更多