1. 程式人生 > >ebay介面例項(Finding api --- 搜尋商品)

ebay介面例項(Finding api --- 搜尋商品)

import java.util.List;

import com.ebay.services.client.ClientConfig;
import com.ebay.services.client.FindingServiceClientFactory;
import com.ebay.services.finding.FindItemsByKeywordsRequest;
import com.ebay.services.finding.FindItemsByKeywordsResponse;
import com.ebay.services.finding.FindingServicePortType;
import com.ebay.services.finding.PaginationInput;
import com.ebay.services.finding.SearchItem;

public class FindItem {
    public static  void main(String[] args) {
        try {
        	ClientConfig config = new ClientConfig();
        	//Production App ID
        	config.setApplicationId("Production App ID");
            FindingServicePortType serviceClient = FindingServiceClientFactory.getServiceClient(config);
            FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
            //搜尋詞語
            request.setKeywords("iphone");
            PaginationInput pi = new PaginationInput();
            //搜尋結果個數
            pi.setEntriesPerPage(4);
            request.setPaginationInput(pi);
            FindItemsByKeywordsResponse result = serviceClient.findItemsByKeywords(request);
            System.out.println("Ack = "+result.getAck());
            System.out.println("Find " + result.getSearchResult().getCount() + " items." );
            List items = result.getSearchResult().getItem();
            for(SearchItem item : items) {
            	System.out.println(item.getTitle());
            	System.out.println(item.getSellingStatus().getCurrentPrice().getValue() 
            			+ " " +item.getSellingStatus().getCurrentPrice().getCurrencyId());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}