简体   繁体   English

使用Content API插入Google Merchant数据供稿

[英]Insert into Google Merchant data feed using Content API

I'm trying to insert some data into my merchant account data feed using the Content API. 我正在尝试使用Content API将一些数据插入我的商家帐户数据Feed中。 Using the code below, I've been given a "POST requests require a Content-length header. That's all we know." 使用下面的代码,我得到了“ POST请求需要Content-length标头。这就是我们所知道的全部。” error, but I've set the content length, so I'm really confused. 错误,但是我已经设置了内容长度,所以我真的很困惑。

One theory I have is that it doesn't know where to put these requests, under my merchant account ID, I have two data feeds, and I'm not sure how to set it to enter into a given data feed. 我的一种理论是,它不知道将这些请求放在哪里,在我的商家帐户ID下,我有两个数据馈送,而且我不确定如何设置它以输入给定的数据馈送。

The XML is stolen from here: https://developers.google.com/shopping-content/batch-operations 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM