Java项目(Eclipse)。沙盒测试应用程序。我使用Sample OAuth应用程序获得了所有必需的令牌和秘密对,并将它们分配给String变量:consumerKey,consumerSecret,accessToken,accessTokenSecret,appToken,companyID。
下一步。我尝试以两种不同的方式授权QBO:直接使用HTTP连接(删除try / catch块):
OAuthConsumer ouathconsumer = new DefaultOAuthConsumer(consumerKey,consumerSecret);
ouathconsumer.setTokenWithSecret(accessToken, accessTokenSecret);
HttpURLConnection urlConnection = null;
URL url = new URL("https://sandbox-quickbooks.api.intuit.com/v3/company/" + companyID + "/customer/4");
urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Connection", "Close");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
ouathconsumer.sign(urlConnection);
urlConnection.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
System.out.println(rd.readLine());
rd.close();
效果很好!但我想做SDK调用。以下源代码给出了错误(try / catch已删除,秘密字符串相同):
IAuthorizer authorizer = new OAuthAuthorizer(consumerKey, consumerSecret, accessToken, accessTokenSecret);
Context context = new Context(authorizer, appToken, ServiceType.QBO, companyID);
DataService service = new DataService(context);
Customer customer=new Customer();
customer.setId("3");
Customer resultCustomer = service.findById(customer);
最后一行给出了当前错误(某些字符串被星号代替):
com.intuit.ipp.exception.AuthenticationException: ERROR CODE:3200, ERROR MESSAGE:message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401, ERROR DETAIL:SignatureBaseString: GET&https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%***%2Fcustomer%2F3&minorversion%3D3%26oauth_consumer_key%***%26oauth_nonce%3D-4488452729022111661%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1450088662%26oauth_token%***%26oauth_version%3D1.0%26requestid%3Dc5bba96ea6894dc3be93588324778891
at com.intuit.ipp.interceptors.HandleResponseInterceptor.execute(HandleResponseInterceptor.java:91)
at com.intuit.ipp.interceptors.IntuitInterceptorProvider.executeResponseInterceptors(IntuitInterceptorProvider.java:94)
at com.intuit.ipp.interceptors.IntuitInterceptorProvider.executeInterceptors(IntuitInterceptorProvider.java:67)
at com.intuit.ipp.services.DataService.executeInterceptors(DataService.java:126)
at com.intuit.ipp.services.DataService.findById(DataService.java:215)
at test_qb.Start_QB.main(Start_QB.java:76)
它说明了auth错误,但是令牌是可以的。请帮帮我。我做错了什么?
答案 0 :(得分:0)
固定。没有什么可以在配置中的URL结尾!
还使用SDK& amp;提供的日志工具。 log4j的