Google Cloud Search Query via node.js Error: Invalid JSON payload received
Google Cloud Search Query via node.js Error: Invalid JSON payload received
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)如有任何帮助,我们将不胜感激。
终于想通了。必须将请求包装在 requestBody JSON.
中
service.query.search({
auth: jwtClient,
requestBody: {
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}
})
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)如有任何帮助,我们将不胜感激。
终于想通了。必须将请求包装在 requestBody JSON.
中service.query.search({
auth: jwtClient,
requestBody: {
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}
})