如何通过EBay Trading API中的GetSellerList调用获取项目的UPC [Java]

时间:2018-05-14 16:40:03

标签: java ebay ebay-api

我尝试使用GetSellerList通过EBay Trading API电话返回返回项目的UPC。

我能够使用以下代码成功执行API调用:

public void getSellerItemsList() throws ApiException, SdkException, Exception
{
    String EBayProfile = "XXXXXXXXXXXX";
    String sellerID = "XXXXXXXXXXXXXX"; 
    ApiContext apiContext = getAPIContext(EBayProfile);

    GetSellerListCall getSellerList  = new GetSellerListCall ();
    getSellerList.setApiContext(apiContext);



    DetailLevelCodeType[] detailLevelCodeType = new DetailLevelCodeType[1];
    detailLevelCodeType[0] = DetailLevelCodeType.RETURN_ALL;
    getSellerList.setDetailLevel(detailLevelCodeType);






    Calendar fromTime = Calendar.getInstance();
    fromTime.add(Calendar.DAY_OF_MONTH, -3);

    Calendar toTime = Calendar.getInstance();
    toTime.setTime(Calendar.getInstance().getTime());


    TimeFilter startTimeFilter = new TimeFilter(fromTime, toTime);
    getSellerList.setStartTimeFilter(startTimeFilter);


    getSellerList.setUserID(sellerID);
    getSellerList.setEnableCompression(true);
    WarningLevelCodeType warningLevel = WarningLevelCodeType.HIGH;
    getSellerList.setWarningLevel(warningLevel);


    PaginationType paginationType = new PaginationType();
    paginationType.setEntriesPerPage(199);
    paginationType.setPageNumber(1);


    ItemType[] items = getSellerList.getEntireSellerList();




    for (ItemType item : items) {
        System.out.println("\nTitle: " + item.getTitle());


        // For some reason this value is always equal to null (never prints)
        if (item.getAttributeArray() != null) {

            AttributeArrayType attributeType = item.getAttributeArray();
            System.out.println("Attributes length: " + attributeType.getAttributeLength());

        }


        // For some reason this value is always equal to null (never prints)
        if (item.getProductListingDetails() != null) {
            UPC = item.getProductListingDetails().getUPC();
            System.out.println("UPC: " + UPC);  
        }  

        // For some reason this value is always equal to null (never prints)
        if (item.getVariations() != null) {
            VariationsType itemVariations = item.getVariations();

            for (int x = 0; x < itemVariations.getVariationLength(); x++) {
                VariationType variation = itemVariations.getVariation(x);
                VariationProductListingDetailsType variationListingDetails = variation.getVariationProductListingDetails();
                UPC = variationListingDetails.getUPC(); // UPC always missing

            }

        }




        // For some reason this value is always equal to null (never prints)
        if (item.getItemSpecifics() != null) {
            NameValueListArrayType itemSpecifics = item.getItemSpecifics();
            NameValueListType[] nameValueList = itemSpecifics.getNameValueList();


            }
        }
    }


}

调用成功执行但UPC为空(无论我在哪里尝试从中提取它,如前面的代码所示)。

EBay Docs明确说明此调用会返回UPC。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

GetSellerList不包括项目细节。

你必须使用eBay购物API调用 - 带有IncludeSelector的GetSingleItem - ItemSpecifics来获取GetSellerList结果中每个项目的UPC

答案 1 :(得分:0)

<块引用>

"GetSingleItem 中不再返回此字段或 GetMultipleItems 调用。要查看 eBay 产品 ID(也称为 ePID) 或全球贸易项目编号(UPC、EAN、ISBN 或 MPN) 列表中的产品(或多变体中的产品变体 列表),请改用交易 API 的 GetItem 调用。”

https://developer.ebay.com/devzone/shopping/docs/callref/getsingleitem.html

但交易 API 的 GetItem 并非为所有用户共享。您只能看到自己的项目

对于 MPN,您可以尝试这样调用“http://open.api.ebay.com/shopping?callname=GetSingleItem&IncludeSelector=ItemSpecifics&responseencoding=XML&appid=XXXX&siteid=0&version=967&ItemID=111111111111”。 无论如何它仍然有效