开发者

Devoloping amazon WS-client using the product API in java

I am developing an Amazon webservice client in java. I have developed all the stubs needed as specified in their site. I could access the title and asin using ItemLookup response. I need to access the price information and image of products. Can someone help me to sort the issue.The code and its response is given below

public class iteml {
   public void itemdetails()
   {
    System.out.println("sample test");
    AWSECommerceService service = new AWSECommerceService();
    service.setHandlerResolver(new awshandlerresolver("secret key"));  // important
    AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

ItemLookupRequest itemLookup = new ItemLookupRequest();
itemLookup.setIdType("ASIN");
itemLookup.getItemId().add("B0036WT3EI");

ItemLookup lookup = new ItemLookup();
lookup.setAWSAccessKeyId("APi key"); // important
lookup.getRequest().add(itemLookup);

ItemLookupResponse response = port.itemLookup(lookup);

String r = response.toString();
System.out.println("response: " + r);


      for (Items itemList:response.getItems())

        for (Item item : itemList.getItem())
        {
           final String asin= item.getASIN();
            System.out.println(asin);
            System.out.println("Title: " +
            item.getItemAttributes().getTitle());
           // Image I=item.getSmallImage();
             // final Image I1 = I;
           // String url=I1.getURL();
           // System.out.println(url);

            String pr=item.getItemAttributes().getListPrice().getFormattedPrice();
           // System.out.println(p);
            System.out.println(pr);
}
}


public static void main(String args[])
    {
      iteml l=new iteml();
      l.itemdetails();
    }
  }

output is B0036WT3EI //asin id Exception in thread "main" java.lang.NullPointerException Title: Samsung LN19C350 19-Inch 720p 60 Hz LCD HDTV (Black) at plugin.iteml.itemd开发者_如何学Goetails(iteml.java:65) at plugin.iteml.main(iteml.java:73) Java Result: 1


I am afraid to be a bit late, but here we go.

After this piece of code:

ItemLookupRequest itemLookup = new ItemLookupRequest();
itemLookup.setIdType("ASIN");
itemLookup.getItemId().add("B0036WT3EI");

add the following line:

itemLookup.setResponseGroup(new String[] { "Images", "ItemAttributes" });

You need to say that you want the ItemLookupRequest request to return a response with both Images and ItemAttributes (from where you extract the ListPrice).

I didn't test in Java, but should work fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜