2014-09-30 99 views
0

這是我第一次嘗試使用Quickbooks API。要開始使用它,我想嘗試一些API調用。Quickbooks身份驗證錯誤 - java sdk quickbooks v3.0

我已經創建的帳戶上的QuickBooks,並獲得以下憑據 -

consumerKey 
consumerSecret 
accessToken 
accessTokenSecret 
appToken 
companyId 

下載IPP java sdk for QuickBooks v3.0和從下載包,我目前使用下面的jar文件 -

ipp-v3-java-devkit-2.3.2-jar-with-dependencies.jar 
ipp-java-qbapihelper-1.2.0-jar-with-dependencies.jar 

這裏是我正在執行的代碼。

import com.intuit.ipp.core.Context; 
import com.intuit.ipp.core.ServiceType; 
import com.intuit.ipp.data.Customer; 
import com.intuit.ipp.exception.FMSException; 
import com.intuit.ipp.security.OAuthAuthorizer; 
import com.intuit.ipp.services.DataService; 

public class TestQuickBooks { 
    public static void main(String[] args) 
    throws FMSException 
    { 
    // following credentials are replaced with my original credential 
    // when executing the code 
    String consumerKey = "..."; 
    String consumerSecret = "..."; 
    String accessToken = "..."; 
    String accessTokenSecret = "..."; 
    String appToken = "..."; 
    String companyId = "..."; 

    try { 
     OAuthAuthorizer oauth = new OAuthAuthorizer(consumerKey, 
                consumerSecret, 
                accessToken, 
                accessTokenSecret); 
     Context context = new Context(oauth, 
            appToken, 
            ServiceType.QBO, 
            companyId); 
     DataService service = new DataService(context); 

     Customer customer1 = new Customer(); 
     customer1.setDisplayName("ABCD"); 

     // this is the line which is throwing exception 
     Customer resultCustomer = service.add(customer1); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 
} 

複製異常消息在這裏 -

com.intuit.ipp.exception.AuthenticationException: ERROR CODE:3200, ERROR MESSAGE:message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401, ERROR DETAIL:null 

我檢查QuickBooks的文檔,但可以;噸弄清楚是什麼原因造成這種身份驗證例外。至於證書,我已經仔細檢查過,這些都是正確的。

我發現快速書有一個API playground,但也沒有運氣。

試過這個API調用 -

https://appcenter.intuit.com/api/v1/PingSecure 

我提供我的憑據,並指定格式,JSON和無URL參數。 它返回下面的消息 -

{ 
    "ErrorMessage": "This API requires Authorization.", 
    "ErrorCode": 22, 
    "ServerTime": "/Date(1412166272838)/" 
} 

我希望是API的操場不應該返回驗證錯誤,因爲我的憑據是正確的。不過,我可以看到API調用的唯一辦法是,當我登錄到API explorer

我真的不知道這是怎麼丟失 - 不能讓從API遊樂場,以及以編程方式使用Java SDK的API調用。

任何幫助,將不勝感激。

回答

0

401建議'驗證'錯誤。

請參考這篇文章,我已經提到過如何使用任何標準的Res​​tclient調用QBO V3端點。

InvalidTokenException: Unauthorized-401

如果您再次看到一個401異常,那麼請生成一組新的accessToken和accessSecret的使用OAuthPlayground工具,並使用那些在java中的devkit。

感謝

1

請添加以下屬性:

Config.setProperty(Config.BASE_URL_QBO,"https://sandboxquickbooks.api.intuit.com/v3/company"); 

前:

DataService service = new DataService(context); 

這爲我工作。