eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>使用eBay JAVA SDK的AddToWatchList API调用的Java例程

技术文档

问题
使用eBay JAVA SDK的AddToWatchList API调用的Java例程
解答
0
人觉得答案有帮助)

总述

   AddToWatchList 允许用户只通过一次请求就能向卖家MyeBay中的Watch List添加多个商品,并自动对加入的商品进行验证。
   此例程使用eBay的 JAVA SDK架构,可调用AddToWatchList 向用户的My eBay Watch List 添加商品,并通过调用GetMyeBuying 验证商品是否已被加入List中。


详述

 例程中使用的主要方法如下,你也可以在文末下载全部的源码。


     public static void main(String [] args){
            AppAddToWatchList aatwl = new AppAddToWatchList();

 


            AddToWatchListCall addToWatchList = new AddToWatchListCall(aatwl.apiContext);
            //
            addToWatchList.setItemIDs(aatwl.itemIds);
            try{
                //make a call to AddToWatchList
                addToWatchList.addToWatchList();
                // call MyeBayBuying to get watch list
                aatwl.getMyeBayBuyingWatchRequest();
            }catch(Exception exc){
                if ( exc instanceof SdkSoapException ) {
                    SdkSoapException sdkSoapExe = (SdkSoapException)exc;
                    ErrorType error = sdkSoapExe.getErrorType();
                    System.out.println("error code: " +error.getErrorCode()+ ", error shot message :"
                            + error.getShortMessage());
                }
                if (exc instanceof ApiException ){
                    ApiException apiExe = (ApiException)exc;
                    ErrorType[] errs = apiExe.getErrors();
                    for (int i=0; i<errs.length; i++){
                        ErrorType error = errs[i];
                        System.out.println("error code " +error.getErrorCode()+ "error shot message"
                                + error.getShortMessage());
                    }
                }
            }//end of try/catch
        }
       
        /*
         * construct GetMyeBayBuying api call request
         **/
        public void getMyeBayBuyingWatchRequest(){
           
            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
                DetailLevelCodeType.ReturnAll
            };
            GetMyeBayBuyingCall gmes = new GetMyeBayBuyingCall(apiContext);
            gmes.setDetailLevel(detailLevels);
           
            // construct data containers that based on ItemListCustomizationType
            gmes.setWatchList
                    (setItemListCustomizationTypeParam(true, 20, 1, ItemSortTypeCodeType.EndTime));
            try{
                gmes.getMyeBayBuying();
            }catch(Exception e){
               
            }
           
            // process returned WatchList data
            PaginatedItemArrayType returnedWatchList = gmes.getReturnedWatchList();
            if (returnedWatchList ==null){
                // no item is found in the watch list
                return;
            }
              
            ItemType[] itemArr =returnedWatchList.getItemArray().getItem();
            for (ItemType item : itemArr){
                for (int i=0; i<itemIds.length; i++){
                    //verify that the watched items are included in the list.
                    if (item.getItemID().toString().equals(itemIds[i])){
                        System.out.println(itemIds[i] +" has been added to the user's watch list");                
                        if (i== (itemIds.length -1))
                            return;
                    }
                }
            }      
    }


 

 版本信息

上面例程基于此特定的Java SDK版本:

API 架构版本 495
Java SDK 版本 javasdk v495.0 Full release

附加文档

 
        附件        • Text document request_header_param.properties.txt
 • HTML document RequestHeaderParam.java
 • HTML document AddItemWithBestOffer.java

 


答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题