Google无法识别API密钥

时间:2020-04-01 15:09:46

标签: javascript node.js google-api

我正在编写使用Google引擎无头搜索Google内容并获得响应的代码。这是我的代码:

const Google = require('relevant-google');
const querystring = require('querystring');
const google = new Google('MYAPIKEY');

google.search(querystring.stringify({ term: 'hola' }))
.then(response => {
    // Do stuff with response.
});

错误:

(node:11389) UnhandledPromiseRejectionWarning: Error: The engine "google" needs a key, please provide it
    at translate (/rbd/pnpm-volume/472f56b4-934e-4e15-9df0-d980557f762f/node_modules/.registry.npmjs.org/translate/1.1.2/node_modules/translate/translate.min.js:1:10976)
at google.search.then (/app/server.js:199:29)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:11389) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:11389) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

出于某种原因,我可以记录响应,但无法访问其属性(例如response.formattedURL

0 个答案:

没有答案