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異常,如果它不能解析的產品。

相關問題