/*
* SoapGetCategoryListings.java
*
* Created on April 11, 2007, 4:56 PM
*/
package com.ebay.api.samples.soap;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import com.ebay.soap.eBLBaseComponents.*;
/**
*
* @author zhuyang
*/
public class SoapGetCategoryListings {
/** Creates a new instance of GetCategoryListingsResponseType */
public SoapGetCategoryListings() {
}
public static void main(String[] args) {
// Read properties file to load the ID's and Tokens.
Properties keys = new Properties();
try {
keys.load(new FileInputStream("keys.properties"));
} catch (IOException e) {
System.out.println(e);
}
String appId = keys.getProperty("appId");
String token = keys.getProperty("token");
String endpoint = keys.getProperty("url");
EBayAPIInterface myService;
//Define the parameters.
String callName;
String siteId = "0";
String version = "505";
String categoryId = "267";
ClientCredentialHandler.setAppId(appId);
ClientCredentialHandler.setToken(token);
SoapGetCategoryListings myObject = new SoapGetCategoryListings();
//GetCategoryListings
callName = "GetCategoryListings";
myService = myObject.setupAPIInterface(endpoint, callName, new Integer(siteId).intValue(), new Integer(version).intValue() );
int page = 1;
myObject.callGetCategoryListings( myService, categoryId, version, page);
}
private void callGetCategoryListings( EBayAPIInterface service, String category, String version,int page ) {
ItemType itemReturn;
PaginationType pageType = new PaginationType();
System.out.println("in page { " + page + " }");
pageType.setEntriesPerPage(new Integer(100));
pageType.setPageNumber(new Integer(page));
GetCategoryListingsRequestType request =null;
GetCategoryListingsResponseType response =null;
try {
//Create the request object
request = new GetCategoryListingsRequestType();
DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
DetailLevelCodeType.ItemReturnCategories
};
request.setDetailLevel(detailLevels);
request.setCategoryID(category);
request.setIncludeFeedback(true);
request.setVersion(version);
request.setPagination(pageType);
response = service.getCategoryListings(request);
ItemType[] itemArray = response.getItemArray().getItem();
if (itemArray !=null){
for (ItemType item: itemArray){
System.out.println(" itemId:" + item.getItemID());
}
}
} catch (Exception e) {
System.err.println("Error locating eBay API Interface: " + e);
System.exit(1);
}
// there are more items, call the function itself recursively
if (response.isHasMoreItems()){
callGetCategoryListings(service, category,version,++page);
}
}
private EBayAPIInterface setupAPIInterface(String baseURL, String callName, int siteId, int version) {
EBayAPIInterface locator = null;
try {
String requestURL = baseURL +"?callname=" + callName
+ "&siteid=" + siteId
+ "&appid=" + ClientCredentialHandler.getAppId()
+ "&version=" + version;
System.out.println("request URL : " + requestURL);
locator = new EBayAPIInterfaceServiceLocator().geteBayAPI(new URL(requestURL));
((EBayAPISoapBindingStub) locator).setTimeout(60000);
} catch (Exception e) {
System.err.println("Error locating eBay API Interface: " + e);
System.exit(1);
}
return locator;
}
}
|