Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API fails because library's google.drive function doesn't exist

Tags:

google-api

I've been following the node.js quickstart example for the google drive API here: enter link description here After fixing an issue with the json looking for an outdated property and a few other minor error corrections, I came across an error that I don't know how to fix (though it's clear what's wrong).

Specifically:

TypeError: google.drive is not a function
at listFiles (D:\myproject\quickstart.js:107:24)
at D:\myproject\quickstart.js:77:7
at D:\myproject\node_modules\google-auth-library\lib\auth\oauth2client.js:95:13
at Request._callback (D:\myproject\node_modules\google-auth-library\lib\transporters.js:113:17)
at Request.self.callback (D:\myproject\node_modules\request\request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (D:\myproject\node_modules\request\request.js:1163:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)

It is quite clear that the function does not exist within the loaded library, it is unclear where it might be located. Poking at the loaded npm module has not led to anything useful so far as "google.drive" just returns results that look like the quickstart code and "drive" appears everywhere.

Does anyone have any clue how to resolve this?

like image 531
JR Smith Avatar asked Jan 03 '23 18:01

JR Smith


1 Answers

If you are using googleapis of latest version ([email protected]), the script of Quickstart has to be modified. Please modify as follows. For node.js, this is confirmed at not only Drive API but also other APIs. I think that the document is not keep up with the updated library.

From :

var google = require('googleapis');

To :

var {google} = require('googleapis');

Note :

  • When you use googleapis with v24 or less, var google = require('googleapis'); can be used.

Reference :

  • https://github.com/google/google-api-nodejs-client/releases/tag/v26.0.0

If this was not useful for your situation, I'm sorry.

like image 54
Tanaike Avatar answered Jan 05 '23 10:01

Tanaike