我如何获得谷歌驱动API认证?



我正在努力让我的身份验证为谷歌驱动器api工作。

这是我当前的代码。

const drive = google.drive({
version: 'v3',
auth: new google.auth.GoogleAuth({
keyFile: 'google-cloud-credentials.json',
scopes: ['https://www.googleapis.com/auth/drive.file'],
}),
});

无论我尝试什么,我得到错误"ENOENT: no such file or directory, open '/var/task/google-cloud-credentials.json'"

我还尝试了以下方法:

keyFile: path.resolve(__dirname, 'google-cloud-credentials.json'),
keyFile: './google-cloud-credentials.json',
keyFile: '../google-cloud-credentials.json',
keyFile: '../../google-cloud-credentials.json',

我应该提一下,我也在部署withServerless,但在过去,我已经能够让它工作。

我找到GoogleAuth类型定义的,您可以简单地使用credentials将身体的凭证,而不是keyFile路径。

之后,我只需要将JSON导入到我的文件中并添加到那里。

你不应该这么做。这就是创建google Auth对象。您必须填写凭据,否则它将不起作用。

可能要再读一遍自述文件。这里有一个oauth的标准实现。也可以随时要求跟进

最新更新