0

나는 자바 애플리케이션으로 Google 쇼핑 마켓에 아이템을 추가하는 솔루션을 개발 중입니다. 튜토리얼은 laste 릴리스의 누락 된 클래스로 인해 혼란 스러웠습니다. 그러나 1.5-beta를 maven으로 설정 한 후에 모든 클래스를 올바르게 typecheck하도록 기본 예제를 만들었습니다. 그러나 나는 여전히 하나의 항목을 추가하는 간단한 작업을 할 수 있습니다. 전체 코드를 게시하는 대신 Product 피드 만 생성하는 부분을 게시하고 있습니다. 내가있는 웹 사이트 링크, 운송 및 세금을 설정 한 구글-API 포럼에있는 사람의 조언에 따라Google 쇼핑 클라이언트 API는 상품 추가 중 400 개의 잘못된 요청 오류를 반환합니다.

<?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> 

:

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로 요청의 내용을 관리 상인 중심.

나는 무엇을해야할지 정말로 모르지만, 누군가는 무슨 일이 일어나고 있는지에 대한 단서를 가지고 있습니까?

답변

0

결국 API의 Google 그룹 덕분에 해결책을 찾았습니다. 이 코드 내 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(); 

을 나는 복사 붙여 넣기 내 원시 XML로 내 삽입 요청을 보낼 content api demo tool을 사용했다. 도구에서 응답에서 오류를 얻을 수 있었지만, 제품을 구문 분석 할 수없는 경우 HttpClient 클래스가 예외를 발생시키기 때문에 Java API를 사용하여 얻은 응답이 다른 것으로 나타났습니다.

관련 문제