Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
469 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 :


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...