0

我无法使用谷歌购物 API ( https://developers.google.com/shopping-content/v2/reference/v2/products/insert ) 获取产品插入请求。我正在向https://www.googleapis.com/content/v2/ shop_id /products?dryRun=true 发送经过身份验证的发布请求,但仅获得状态:400 并显示错误消息:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "[product] INSERT request must specify product"
   }
  ],
  "code": 400,
  "message": "[product] INSERT request must specify product"
 }
}

我的请求看起来像这样(为了简洁和 ssl 加密而缩短)

POST /content/v2/<removed>/products?dryRun=true HTTP/1.1
Host: www.googleapis.com
Content-Length: 2102
accept-encoding: gzip, deflate
authorization: Bearer <removed>
user-agent: Python-httplib2/0.9.1 (gzip)

{
  "offerId": 4572, 
  "gtin": "4048669296057", 
  "googleProductCategory": "Apparel & Accessories > Clothing", 
  "targetCountry": "se", 
  "title": "Puma Sweat Pants", 
  "onlineOnly": true, 
  "price": {
    "currency": "SEK", 
    "value": "1337"
  }, 
  "channel": "online", 
  "contentLanguage": "sv", 
  "brand": "Puma", 
  "link": "http://example.com/produkt/puma-sweat-pants"
}

我知道请求已正确验证,因为我可以删除验证并获得不同的消息。Googles 常见错误页面 ( https://developers.google.com/shopping-content/v2/how-tos/common-errors ) 表明这是一个批处理作业,但那将是 URL https://www.googleapis .com/content/v2/products/batch

4

1 回答 1

1

我找到了麻烦的原因:我没有发送Content-Type: application/json标头。

于 2015-08-04T08:36:25.543 回答