0

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

我的一个理论是它不知道将这些请求放在哪里,在我的商家帐户 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")
4

1 回答 1

0

您是否在发布之前进行身份验证?

https://developers.google.com/shopping-content/getting-started/authentication

于 2014-05-22T15:09:24.850 回答