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

搜 索
首页>API开发者平台>技术文档>GetCategoryListing 调用GetCategoryListings

技术文档

问题
GetCategoryListing 调用GetCategoryListings
解答
0
人觉得答案有帮助)

 

总述

   此例程使用Apache axis生成的eBay SOAP API和代码存根调用GetCategoryListings


详述

  例程使用Apache Axis wsdj2java工具来生成对应eBay API WSDL的Java代码存根 

  这是SoapGetCategoryListings的Java类。完整源码附在文末供下载。

/*
 * 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;
    }
   
}


版本信息

例程基于此特定的版本信息:

API 架构版本 503


 

附件

 • HTML document client-config.wsdd
 • HTML document keys.properties
 • HTML document SoapGetCategoryListings.java
 • HTML document ClientCredentialHandler.java

 

 


答案对您有帮助吗?

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