总述
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版本:
附加文档
附件 •
request_header_param.properties.txt
•
RequestHeaderParam.java
•
AddItemWithBestOffer.java