Google 驱动器 API - 无法读取未定义的属性“OAuth2" [英] Google drive API - Cannot read property 'OAuth2' of undefined

查看:13
本文介绍了Google 驱动器 API - 无法读取未定义的属性“OAuth2"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 本快速入门教程,最终能够从我的应用程序下载某些文件.

I am following this quickstart tutorial to eventually be able to download certain files from my application.

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

As I followed through with the tutorial I got the error Cannot read property 'OAuth2' of undefined and it's coming from that line:

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

I already installed googleapis @ 27 and here's my 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 报告了这件事,但为了希望今天完成这项工作,这里有没有人遇到过类似的问题?

I have already reported that to google but in the interest of hopefully getting this done today has anyone here faced a similar issue?

推荐答案

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

Please try const {google} = require('googleapis');. From v26.0.0, it the usage was changed. https://github.com/google/google-api-nodejs-client/releases/tag/v26.0.0

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

Unfortunately, after the version of v25.0.0, some bugs for APIs and the options are reported. I believe that these bugs are removed in the future. So if for APIs and the options you use, some errors occur, please modify the version of googleapis, and try again.

这篇关于Google 驱动器 API - 无法读取未定义的属性“OAuth2"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆