API 电子表格 Google

API SpreadSheets Google

执行文档代码时 https://developers.google.com/sheets/quickstart/nodejs?fbclid=IwAR0KmCnMNwsPkzuB93pB8YKaWot7IkAtxWqgLANR1Z08kuRKSl-r3DbqMrY#step_3_set_up_the_sample , 将 URL 的密钥(google 帐户进行身份验证后)

出现这个错误:

node: 5868) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: C
llback must be a function
in maybeCallback (fs.js: 129: 9)
in Object.writeFile (fs.js: 1156: 14)
in storeToken (C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ api.js: 100: 6)
in C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ api.js: 79: 7
in getTokenAsync.then.r (C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ node_modules \ go
gle-auth-library \ build \ src \ auth \ oauth2client.js: 97: 51)
in process._tickCallback (internal / process / next_tick.js: 68: 7)
node: 5868) UnhandledPromiseRejectionWarning: Rejection of uncontrolled promise. This e
Ror originated either by throwing inside an asynchronous function without a capture bl
ck, or rejecting a promise that was not handled with .catch (). (Rejection ID
one)
node: 5868) [DEP0018] DeprecationWarning: unmanaged promise rejects are obsolete
In the future, rejections of promise that are not handled will end the N
Process .js with a non-zero exit code.

这是由于更新了 NodeJS fs 模块。只需添加一个空函数作为第三个参数:

fs.writeFile(TOKEN_PATH, JSON.stringify(token), function(){});

或使用 ES6 语法:

fs.writeFile(TOKEN_PATH, JSON.stringify(token), () => {});

请参阅此 post 以获取更多详细信息: