Google drive API - Cannot read property 'OAuth

2019-01-20 19:13发布

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

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

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"
  }
}

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

1条回答
相关推荐>>
2楼-- · 2019-01-20 19:40

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

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.

References :

查看更多
登录 后发表回答