【发布时间】: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。请将其发布为答案,以便我可以将其标记为解决方案
-
感谢您的关注。我用附加信息发布了我的答案。请确认。