Javascript 节点js Google驱动器api错误
我正在尝试使用访问Google Drive API,以便将一些文件上载到我的驱动器帐户,但我遇到了以下错误:Javascript 节点js Google驱动器api错误,javascript,node.js,google-api,google-drive-api,node-modules,Javascript,Node.js,Google Api,Google Drive Api,Node Modules,我正在尝试使用访问Google Drive API,以便将一些文件上载到我的驱动器帐户,但我遇到了以下错误: drive.files.create({ ^ ReferenceError: drive is not defined at Object.<anonymous> (/Applications/MAMP/htdocs/google_drive/upload.js:16:1) at Module._compile (module.js:643:30)
drive.files.create({
^
ReferenceError: drive is not defined
at Object.<anonymous> (/Applications/MAMP/htdocs/google_drive/upload.js:16:1)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
有人能帮助解决这个问题吗?您需要先定义它
var drive = google.drive("v3");
在谷歌的文档中查找适当的方法:
您需要首先定义它
var drive = google.drive("v3");
在谷歌的文档中查找适当的方法:
我认为你的
constgoogle
声明应该使用一个解构赋值。如:
const {google} = require(googleapis);
然后声明drive
,如下所示:
const drive = google.drive({version: 'v3', auth});
其中,
auth
是授权的OAuth2客户端 我认为您的const google
声明应该使用一个解构赋值。如:
const {google} = require(googleapis);
然后声明drive
,如下所示:
const drive = google.drive({version: 'v3', auth});
其中,
auth
是授权的OAuth2客户端 您尚未在代码中定义驱动器
。一旦你这样做了,它就会工作。你还没有在你的代码中定义drive
。一旦你这样做了,它就会工作。为什么不定义v3?为什么不定义v3?