使用Content API插入Google Merchant数据Feed

时间:2013-09-25 12:41:18

标签: ruby-on-rails google-api httpclient

我正在尝试使用Content API将一些数据插入到我的商家帐户数据Feed中。使用下面的代码,我得到了一个“POST请求需要内容长度标题。这就是我们所知道的。”错误,但我已经设置了内容长度,所以我真的很困惑。

我的一个理论是,它不知道在哪里提出这些请求,在我的商家帐户ID下,我有两个数据源,我不知道如何将其设置为输入给定的数据源。

XML从这里被盗:https://developers.google.com/shopping-content/batch-operations

@feed = '<?xml version="1.0"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
        xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
        xmlns:g="http://base.google.com/ns/1.0"
        xmlns:batch="http://schemas.google.com/gdata/batch">

    <entry xmlns="http://www.w3.org/2005/Atom"
        xmlns:sc="http://schemas.google.com/structuredcontent/2009"
        xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
        xmlns:app="http://www.w3.org/2007/app">
        <batch:operation type="INSERT"/>
        <title>Switch 1</title>
        <content type="text">A new item available...</content>
        <link rel="alternate" type="text/html" href="http://www.example.com/sku123"/>
        <sc:id>SKU123</sc:id>
        <sc:content_language>en</sc:content_language>
        <sc:target_country>US</sc:target_country>
        <scp:google_product_category>Electronics  &gt; Networking  &gt; Hubs  &amp;
        Switches</scp:google_product_category>
        <scp:condition>new</scp:condition>
        <scp:price unit="USD">25</scp:price>
        <scp:availability>in stock</scp:availability>
    </entry>


    <entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:sc="http://schemas.google.com/structuredcontent/2009"
    xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
    xmlns:app="http://www.w3.org/2007/app">
      <batch:operation type="INSERT"/>
      <title>Switch 2</title>
      <content type="text">Another item available...</content>
      <link rel="alternate" type="text/html" href="http://www.example.com/sku124"/>
      <sc:id>SKU124</sc:id>
      <sc:content_language>en</sc:content_language>
      <sc:target_country>US</sc:target_country>
      <scp:google_product_category>Electronics  &gt; Networking  &gt; Hubs  &amp;
    Switches</scp:google_product_category>
      <scp:condition>new</scp:condition>
      <scp:price unit="USD">50</scp:price>
      <scp:availability>in stock</scp:availability>
     </entry>

    </feed>'


    http = HTTPClient.new
    @output = http.post('https://content.googleapis.com/content/v1/<myMerchantID>/items/products/schema/batch', {},"content"=> @feed, "Content-length"=>@feed.length.to_s, "GData-Version"=> "1", "Authorization" => "AuthSub token=myToken", "Content-Type"=> "application/atom+xml")

1 个答案:

答案 0 :(得分:0)