googleapis node.js库在尝试查询云搜索API时返回以下错误。
Error: Invalid JSON payload received. Unknown name \"requestOptions[searchApplicationId]\": Cannot bind query parameter. Field 'requestOptions[searchApplicationId]' could not be found in request message."
有效载荷与此处https://developers.google.com/cloud-search/docs/reference/rest/v1/query/search完全相同。存在requestOptions [searchApplicationId],如果将其删除,则会出现错误消息,提示需要searchApplicationId。
代码:
const {google} = require('googleapis');
const service = google.cloudsearch({version: 'v1'});
service.query.search({
auth: jwtClient,
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}).then((res) => {
console.log(JSON.stringify({results:res.results.length}));
console.log(JSON.stringify({resultsInfo:res.results[0]}));
}).catch((err) => {
console.error('Unexpected error with cloud search API.');
console.error(err.toString());
});
我想念一些简单的东西吗?这是Google客户端库的问题吗? (https://github.com/googleapis/google-api-nodejs-client)我们将不胜感激。
答案 0 :(得分:0)
最后弄清楚了。必须将请求包装在 requestBody JSON中。
service.query.search({
auth: jwtClient,
requestBody: {
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}
})