ebay ordersAPI - API请求中的身份验证令牌验证失败

时间:2016-12-23 15:58:21

标签: java soap wsdl ebay ebay-api

我试图将ebay的order API与我的应用程序整合在一起。我使用以下代码来执行此操作。

public class Order {

    public static void getOrders() throws ApiException, SdkException, Exception {


        ApiContext apiContext = new ApiContext();
        ApiCredential cred = apiContext.getApiCredential();
        //Set Auth Token and server URL for sandbox
        cred.seteBayToken("v^1.1#i^1#r^0#p^1#I^3#f^0#t^H4sIAAAAAAAAAOVXa2wUVRTudreFggWJBuQRsw6GgM3MzmNnOzth124ppBX6gF0rrSi5M3OnHdmdGefedXcT1Fpj44+S+EPQCIYmFSNGDFETpUqC4SEJD43WKJGgCYFgNNWgEdRovLNdyrYqRVgNifNncs8599zvfOec+2B7Kqvu6mvsu1DtmVI+0MP2lHs83HS2qrKiZoa3fF5FGVtk4BnoubPH1+s9txSBVNKW10BkWyaC/mwqaSI5L4xQaceULYAMJJsgBZGMVTkea14l8wwr246FLdVKUv6mhggFQVjQFI7TVRUKYSlMpOYlnwkrQgVDgNd5EOYkDbKKWkv0CKVhk4kwMHGE4lkuRHM8zQsJTpQFSRY5JixKnZS/HTrIsExiwrBUNA9Xzs91irBeGSpACDqYOKGiTbEV8dZYU8PylsTSQJGvaIGHOAY4jcaPllka9LeDZBpeeRmUt5bjacIBQlQgOrrCeKdy7BKYa4CfpzqkhhRJ4SRWF2u5oCCWhMoVlpMC+Mo4XImh0XreVIYmNnBuMkYJG8pDUMWFUQtx0dTgd3+r0yBp6AZ0ItTy+lhHrK2NiuJu4CBgIhpDhOl4/Vo6FBR1CfCKRnNaWGI1LlRYZNRTgeIJqyyzTM1wCUP+FgvXQ4IYTuSFL+KFGLWarU5Mxy6aYrvaS/wFhU43oaMZTONu080pTBES/Pnh5OyPzcbYMZQ0hmMeJiry9EQoYNuGRk1U5uuwUDpZFKG6MbblQCCTyTAZgbGcrgDPslxgbfOquNoNU4Aq2Lq9nkXG5BNoIx+KCslMZMg4ZxMsWVKnBIDZRUV5kpLacIH38bCiE6V/EhTFHBjfDaXqDiCxnBgEUFcAK0JBKEV3RAsFGnBxQAXk6BRwNkBsJ4EKaZXUWToFHUOTBVHnBUmHtBYK63QwrOu0ImpkPR1CFkJFUcPS/6VJrrbMlyUNokyQMitZrZekzhsthKF2tXX+l6HFVcuGbVbSUHP/aWxur08an+BobcDBufp0jozjMJkkv+sKV81ncn0JN62SJPIf9Mu1xW0AfGNFzAUlXmRrRYG7vrjIJeaGiku1Uoy7/TIOsLHlMASanYSIcSCy0g65dDGt7mGcsDZAk2xv2LGSSei0Xx8LyG3iG4sHdz4iDoBtML4nducpIdwELECid6Xr86D9xXZ/ZxRQ0jmmK01agwDRoPMvHOyB8U+MaFn+43o9e9lezx7ySmFrWZqrYZdUeu/1eW+ikIEhya2pKVaWMYDOIKPLJDdoBzIbYM4GhlNe6Wk+3d/xeNHjZuAB9rax502Vl5te9NZhF1zWVHAz51RzIY7nBU4UJJHrZBde1vq42b5bX5n7yfKT9yx+8OfDvwpooV8ufy2UY6vHjDyeijJfr6fs5AtfPJWjz/3++vB737YE5w7/uPFMtmL+Las/bF1y980t/Ofvnm0Oex+7OLio7/v7vY8eGfKMVL/zzavH4vs736L3N7w5palCOc8PDfbs277i5Tlbl2w+kr19955mH9fwW/3qWReozqn6mQMXI/4PqnYE9rX3D7RWTkuxzvvPz59mHWgUN9UN9O5aMOT5VHp6+rrnziYC84JHZx6r6VJ/2LjjkQP9W0cursnsrGHve/hL9qftw90rB/teShyqnrXNfntl4+bM+V11ddtO8DuHvju+82DjicWnjo+88cuiur1TzcOZjs++GplR9uT+o8c+uuPgMxS/eHjBqY9Pv7hJaTx0/uuujnXPbpnd31I/ODx7NI1/AO3YK892DgAA");
        apiContext.setApiServerUrl("https://api.sandbox.ebay.com/wsapi");
        ApiLogging apiLogging = new ApiLogging();
        apiContext.setApiLogging(apiLogging);        

        // Set the site based on the seller - for UK sellers, set it to SiteCodeType.UK
        // for US, set to SiteCodeType.US
        apiContext.setSite(SiteCodeType.US); 

        // set detail level to ReturnAll
        DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[]{DetailLevelCodeType.RETURN_ALL};

        // define CreateTimeFrom and CreateTimeTo filters
        // set "To" to the current time 
        Calendar to = new GregorianCalendar(TimeZone.getTimeZone("GMT")).getInstance();         
        Calendar from = (GregorianCalendar) to.clone();

        // In this example we set "From" to 30 mins from current time - you need to set it to the last time you made the call
        from.add(to.MINUTE,-30);        

        GetOrdersCall getOrders = new GetOrdersCall(apiContext);
        getOrders.setDetailLevel(detailLevels);
        getOrders.setCreateTimeFrom(from);
        getOrders.setCreateTimeTo(to);

        OrderType[] orders = getOrders.getOrders();
        System.out.println("Finished " + orders.length);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            getOrders();
        } catch (ApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SdkException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

我使用以下方式获得了令牌。

1)使用ebay sandbox

注册测试帐户

2)Login到ebay开发者帐户

3)我的用户帐户> ebay的Auth令牌>获取oAuth ApplicationToken

当我将该令牌复制到我的程序并执行时,我得到了以下异常。

com.ebay.sdk.SdkSoapException: Validation of the authentication token in API request failed.
    at com.ebay.sdk.SdkSoapException.fromSOAPFaultException(Unknown Source)
    at com.ebay.sdk.ApiCall.executeByApiName(Unknown Source)
    at com.ebay.sdk.ApiCall.execute(Unknown Source)
    at com.ebay.sdk.call.GetOrdersCall.getOrders(GetOrdersCall.java:231)
    at ebayHelloWorld.Order.getOrders(Order.java:50)
    at ebayHelloWorld.Order.main(Order.java:56)

有人可以建议我在这里弄错了。更快的回复更受欢迎。感谢

2 个答案:

答案 0 :(得分:4)

你应该得到这样的令牌: 1.打开developer.ebay.com并登录 2.在此处获取用户令牌 - > Auth'n'Auth(不是oauth) - >登录沙箱,您可以看到令牌复制它。 在进行交易SOAP调用或使用交易SDK时,您需要使用https://api.sandbox.ebay.com/wsapi用于沙箱环境或https://api.ebay.com/wsapi用于生产。

答案 1 :(得分:0)

正确的方法是从“Auth n Auth'”中获取令牌。如@kai所述。生成令牌的分步过程详细解释在此blog帖子中。