簡體   English   中英

Google Shopping API node.js產品插入返回“INSERT請求必須指定產品”錯誤

[英]Google Shopping API node.js product insert returns “INSERT request must specify product” error

我正在嘗試使用以下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' } ] }

這是我的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);
});

在此先感謝您的幫助!

產品的插入功能具有以下特征

/** 
* 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 
*/ 

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

正如您所看到的那樣,param對象有一個名為resource的屬性,它是您要發送給服務的實際對象。

因此,您需要將傳遞給插入函數的參數從{merchantId: MERCHANTID ,product:product},...更改為{merchantId: MERCHANTID ,resource:product},...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM