eBay GetMyeBaySellings在XML请求中找不到XML <RequestPassword>或<RequestToken>

时间:2019-07-06 15:52:35

标签: java ebay-api ebay-sdk

我想使用eBay-API获取我出售的物品。这是我的代码:

ApiContext apiContext = new ApiContext();
ApiCredential credential = apiContext.getApiCredential();
ApiAccount acc = new ApiAccount();
acc.setApplication("app-id");
acc.setDeveloper("dev-id");
acc.setCertificate("cert");
eBayAccount eBayAccount = new eBayAccount();
eBayAccount.setPassword("ebay user");
eBayAccount.setUsername("ebay password");
credential.setApiAccount(acc);
credential.seteBayAccount(eBayAccount);
apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
GetMyeBaySellingCall call = new GetMyeBaySellingCall(apiContext);
GetMyeBaySellingRequestType requestType = new GetMyeBaySellingRequestType();
call.setMyeBaySellingRequest(requestType);
ItemListCustomizationType lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.BID_COUNT);
requestType.setActiveList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.PRICE);
requestType.setSoldList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.END_TIME);
requestType.setUnsoldList(lc);

lc = new ItemListCustomizationType();
lc.setInclude(new Boolean(true));
lc.setIncludeNotes(new Boolean(true));
lc.setSort(ItemSortTypeCodeType.START_TIME);
requestType.setScheduledList(lc);

call.getMyeBaySelling();

GetMyeBaySellingResponseType resp = call.getReturnedMyeBaySellingResponse();

APIAccount配置有来自ebay开发人员站点的数据,eBayAccount充满了我要为其获取项目的帐户的凭据。但是,这导致以下异常:

Exception in thread "main" com.ebay.sdk.SdkSoapException: No XML <RequestPassword> or <RequestToken> was found in XML Request.
    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.GetMyeBaySellingCall.getMyeBaySelling(GetMyeBaySellingCall.java:150)

用户已通过应用程序身份验证,并且API-URL正确。此外,应用和用户均已通过生产验证。
谁能帮我吗?

2 个答案:

答案 0 :(得分:0)

        ApiContext apiContext = new ApiContext();
        ApiCredential credential = apiContext.getApiCredential();
        credential.seteBayToken("token from developer central");
        apiContext.setApiServerUrl("https://api.ebay.com/wsapi");
        GetMyeBaySellingCall call = new GetMyeBaySellingCall(apiContext);

答案 1 :(得分:0)

我想举一个更详细的例子。我的应用程序从eBay下载我的帐户(仅限我的帐户)的订单。在这种情况下,我不需要提供App ID,Dev ID或Cert ID。我只需要在eBay上生成Auth'n'Auth令牌并将其用作我的凭证即可。

天蓝色功能

@FunctionName("LoadOrders")
public void run(@TimerTrigger(name = "keepAliveTrigger", schedule = "0 5 3 3 * *") String timerInfo, ExecutionContext context)
        throws ApiException, SdkException, Exception {

    ZonedDateTime startDate = ZonedDateTime.now(Constants.TIMEZONE)
        .minusMonths(1)
        .with(TemporalAdjusters.firstDayOfMonth())
        .withHour(0)
        .withMinute(0)
        .withSecond(0)
        .withNano(0);

    ZonedDateTime endDate = ZonedDateTime.now(Constants.TIMEZONE)
        .with(TemporalAdjusters.firstDayOfMonth())
        .withHour(0)
        .withMinute(0)
        .withSecond(0)
        .withNano(0)
        .minusSeconds(1);

    GetOrdersCall call = new GetOrdersCall(apiContext());
    call.setCreateTimeFrom(GregorianCalendar.from(startDate));
    call.setCreateTimeTo(GregorianCalendar.from(endDate));

    for (OrderType orderType : call.getOrders()) {
        System.out.println(orderType);
    }
}

apiContext()方法的定义如下:

public final static String EBAY_TOKEN = "AgAAAA**AQAA.....a4A9t+/";

public final static String API_SERVER_URL = "https://api.ebay.com/wsapi";

private ApiContext apiContext() {
    // credential
    ApiCredential credential = new ApiCredential();
    credential.seteBayToken(EBAY_TOKEN);

    // context
    ApiContext apiContext = new ApiContext();
    apiContext.setApiCredential(credential);
    apiContext.setApiServerUrl(API_SERVER_URL);
    apiContext.setCallRetry(callRetry());

    return apiContext;
}

以防万一您需要它...

private CallRetry callRetry() {
    CallRetry retry = new CallRetry();
    retry.setMaximumRetries(3);
    retry.setDelayTime(3000);
    return retry;
}

您可以在https://developer.ebay.com/my/auth/?env=production(截至2019年12月25日)获得“ eBay令牌”。

这是屏幕的样子:

ebay screen shot