我在使用Google购物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"
}
我知道请求已经过正确身份验证,因为我可以删除身份验证并获取其他消息。 谷歌常见错误页面(https://developers.google.com/shopping-content/v2/how-tos/common-errors)表明这是一个批处理作业,但那将是网址https://www.googleapis.com/content/v2/products/batch
答案 0 :(得分:0)
我找到了解决问题的原因:我没有发送Content-Type: application/json
标题。