0

我正在研究一个解决方案,用Java应用程序在谷歌购物市场添加项目。 继教程是一个真正的混乱,因为缺少班乐特发布的,与Maven设置1.5测试版后,但我设法让基地为例,正确类型检查的所有类。不过,我仍然可以通过简单的任务添加一个项目。我发布了只创建产品Feed的部分,而不是发布整个代码。谷歌商店客户端API返回400错误的请求错误,同时添加一个项目

private Product createProduct(String id) { 
    Product product = new Product(); 
    product.title = "Red wool sweater"; 
    product.content = 
     new Content(
      "text", 
      "Comfortable and soft, this sweater will keep you warm on those " 
      + "cold winter nights. Red and 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 a 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; 
    } 

我设法采取的HTML请求的内容:

<?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 and soft, this sweater will keep you warm on those cold winter nights. Red and 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 &amp; 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> 

继在谷歌的API论坛一个人,我已经设置了网站链接,运费和税金的的建议商人中央。

我真的不知道该怎么做,有人对发生了什么事情有线索?

回答

0

最后,我找到了一个解决方案,感谢api的谷歌组织。 我能得到我的http请求这段代码的内容之后:

// 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(); 

我用content api demo tool通过复制粘贴我的原始XML送我插入请求。 从工具,我能得到的响应中的错误,但我注意到,我得到通过使用Java API的反应是不同的,因为HttpClient的类trows异常,如果它不能解析的产品。

相关问题