Google Shopping API node.js 产品插入返回“INSERT 请求必须指定产品”错误

use*_*042 1 javascript node.js google-shopping-api google-api-nodejs-client

我尝试使用以下 node.js 代码将产品插入 Google Shopping API,但不断收到错误消息:

{ [Error: [product] INSERT request must specify product]
code: 400,
errors:
[ { domain: 'global',
   reason: 'required',
   message: '[product] INSERT request must specify product' } ] }
Run Code Online (Sandbox Code Playgroud)

这是我的 javascript 代码(我在这里使用节点客户端: https: //github.com/google/google-api-nodejs-client/):

var google = require('googleapis');

var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(*OAUTHDETAILS*);

oauth2Client.setCredentials({
    access_token: '*ACCESSTOKEN*',
  //refresh_token: 'REFRESH TOKEN HERE'
});

var content = google.content({ version: 'v2', auth: oauth2Client });

var product = {
    "channel": "online",
    "contentLanguage": "en",
    "offerId": *PRODUCTID*,
    "targetCountry": "us",
    "identifierExists": false,
    "condition": "new",
    "link": "*PRODUCTLINK*",
    "price": {
        "currency": "usd",
        "value": *VALUE*
    },
    "title": *PRODUCTTITLE*,
    "availability": "in stock",
    "description": *DESCRIPTION*,
    "googleProductCategory": *PRODUCTCATEGORY*,
    "ageGroup": "adult",
    "color": *PRODUCTCOLOR*,
    "gender": "unisex",
    "sizes": [
        "XS",
        'S',
        'M',
        'L',
        'XL'
    ],
    "imageLink": *IMGURL*
};

content.products.insert({merchantId:*MERCHANTID*,product:product},function(err, resp) {
    // handle err and response
    console.log(err);
    console.log(resp);
});
Run Code Online (Sandbox Code Playgroud)

预先感谢您的任何帮助!

Boo*_*750 5

产品的Insert函数具有以下签名

/** 
* content.products.insert 
* 
* @desc Uploads a product to your Merchant Center account. 
* 
* @alias content.products.insert 
* @memberOf! content(v2) 
* 
* @param  {object} params - Parameters for request 
* @param  {boolean=} params.dryRun - Flag to run the request in dry-run mode. 
* @param  {string} params.merchantId - The ID of the managing account. 
* @param  {object} params.resource - Request body data 
* @param  {callback} callback - The callback that handles the response. 
* @return {object} Request object 
*/ 
Run Code Online (Sandbox Code Playgroud)

此签名可以在文件中找到:https://github.com/google/google-api-nodejs-client/blob/master/apis/content/v2.js

正如您所看到的,param 对象有一个名为 Resource 的属性,它是您要发送到服务的实际对象。

因此,您需要将传递给插入函数的参数从更改为{merchantId:MERCHANTID,product:product},...{merchantId:MERCHANTID,resource:product},...