google shop client API returns 400 bad request error while adding an item -
i'm working on solution add items in google shopping market java application. following tutorial real mess because of missing classes of laste release, after setting 1.5-beta maven managed make base example typecheck correctly classes. still can make simple task of adding 1 item. instead of posting whole code i'm posting part creates product feed.
private product createproduct(string id) { product product = new product(); product.title = "red wool sweater"; product.content = new content( "text", "comfortable , soft, sweater keep warm on " + "cold winter nights. red , blue stripes."); product.appcontrol = new appcontrol(); product.appcontrol.addrequireddestination("productads"); product.externalid = id; product.lang = "it"; product.country = "it"; product.condition = "nuovo"; product.price = new price("eur", new bigdecimal("12.99")); product.googleproductcategory = "sporting goods > exercise & fitness > cardio machines > exercise bikes"; // add link link link = new link(); link.rel = "alternate"; link.href = homepage + "item1-info-page.html"; link.type = "text/html"; product.links.add(link); //shipping list<com.google.api.client.sample.structuredcontent.model.shipping> shipping = new arraylist<com.google.api.client.sample.structuredcontent.model.shipping>(); com.google.api.client.sample.structuredcontent.model.shipping s = new com.google.api.client.sample.structuredcontent.model.shipping(); s.shippingcountry="it"; price p = new price(); p.unit = "eur"; p.value = new bigdecimal("0"); s.shippingprice= p; //s.shippingregion="" s.shippingservice = "speedy shipping - ground"; shipping.add(s); product.shippingrules = shipping; //tax //useless in italy // set image links list<string> imagelinks = new arraylist<string>(); imagelinks.add("http://www.example.com/image1.jpg"); imagelinks.add("http://www.example.com/image2.jpg"); product.imagelinks = imagelinks; return product; }
i managed take content of html request:
<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/atom" xmlns:app="http://www.w3.org/2007/app" xmlns:sc="http://schemas.google.com/structuredcontent/2009" xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"><app:control><sc:required_destination dest="productads" /> </app:control> <content type="text"> comfortable , soft, sweater keep warm on cold winter nights. red , blue stripes.</content> <link href="http://www.joinstore.it/item1-info-page.html" rel="alternate" type="text/html" /> <sc:adult>false</sc:adult><sc:content_language>it</sc:content_language> <sc:id>1234567</sc:id> <sc:image_link>http://www.example.com/image1.jpg</sc:image_link> <sc:image_link>http://www.example.com/image2.jpg</sc:image_link> <sc:target_country>it</sc:target_country> <scp:condition>nuovo</scp:condition> <scp:featured_product>false</scp:featured_product> <scp:google_product_category>sporting goods > exercise & fitness > cardio machines > exercise bikes</scp:google_product_category> <scp:price unit="eur">12.99</scp:price> <scp:shipping><scp:shipping_country>it</scp:shipping_country> <scp:shipping_price unit="eur">0</scp:shipping_price> <scp:shipping_service>speedy shipping - ground</scp:shipping_service></scp:shipping> <title>red wool sweater</title> </entry>
following advice of guy in google-api forum i've set website link, shipping , taxes in merchant central.
i don't know do, has clue of what's going on?
in end found solution google groups of api. after able content of http request code:
// http request httprequest request = requestfactory.buildpostrequest(new googleurl(url), atomcontent); file f = new file(main.base_folder_path + "ciao.xml"); fileoutputstream out = new fileoutputstream(f); request.getcontent().writeto(out); out.close(); httpresponse re = null; re = request.execute();
i used content api demo tool send insert request copy-pasting raw xml. tool able errors in response, noticed response using java api different, because httpclient class trows exception if can't parse product.
Comments
Post a Comment