【问题标题】:API SpreadSheets GoogleAPI 电子表格 Google
【发布时间】:2019-04-18 00:11:30
【问题描述】:

在执行文档的代码时 https://developers.google.com/sheets/quickstart/nodejs?fbclid=IwAR0KmCnMNwsPkzuB93pB8YKaWot7IkAtxWqgLANR1Z08kuRKSl-r3DbqMrY#step_3_set_up_the_sample ,放上网址的key后(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.

【问题讨论】:

  • 这就是你的全部代码吗?你知道是哪一行触发了错误吗?
  • 你可能需要也可能不需要在 Github 上报告问题
  • 所有代码都在链接中
  • 我看了,但我没有在其中的任何地方找到任何setToken 函数
  • 对不起,我的意思是storeToken

标签: google-sheets-api


【解决方案1】:

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

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

或者使用 ES6 语法:

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

更多详情请参考这篇文章:Why node 10 has made it mandatory to pass callback on fs.writeFile()?

【讨论】:

    猜你喜欢
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多