【问题标题】:Google drive API - Cannot read property 'OAuth2' of undefinedGoogle 驱动器 API - 无法读取未定义的属性“OAuth2”
【发布时间】:2018-09-25 15:35:43
【问题描述】:

我关注this quickstart tutorial 最终能够从我的应用程序中下载某些文件。

当我按照教程进行操作时,我收到了错误 Cannot read property 'OAuth2' of undefined,它来自该行:

const fs = require('fs');
const readline = require('readline');
const google = require('googleapis');
const OAuth2Client = google.auth.OAuth2; << google.auth = undefined
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly'];
const TOKEN_PATH = 'credentials.json';
// the rest of the code is exactly as it is in the tutorial

我已经安装了 googleapis @ 27,这是我的 package.json

{
  "name": "temp-google-drive-api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "googleapis": "^27.0.0"
  }
}

我已经向 google 报告了这件事,但为了希望今天完成这项工作,这里有没有人遇到过类似的问题?

【问题讨论】:

  • 请尝试const {google} = require('googleapis');。从 v26.0.0 开始,用法发生了变化。 github.com/google/google-api-nodejs-client/releases/tag/v26.0.0
  • 成功了,谢谢@Tanaike。请将其发布为答案,以便我可以将其标记为解决方案
  • 感谢您的关注。我用附加信息发布了我的答案。请确认。

标签: node.js google-drive-api


【解决方案1】:

请尝试const {google} = require('googleapis');。从 v26.0.0 开始,它的用法发生了变化。 https://github.com/google/google-api-nodejs-client/releases/tag/v26.0.0

不幸的是,在 v25.0.0 版本之后,报告了一些 API 和选项的错误。我相信这些错误将来会被删除。所以如果API和你使用的选项出现一些错误,请修改googleapis的版本,然后重试。

参考资料:

【讨论】:

    猜你喜欢
    • 2018-09-26
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 2022-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多