【发布时间】:2019-12-24 17:41:59
【问题描述】:
我需要以编程方式修改我的 Google 云端硬盘,以创建文件夹并将一堆文件上传到其中,然后在需要时删除该根文件夹并重做整个过程。
我创建了一个具有服务帐户的项目,然后下载了 JSON 并将其存储在我的计算机上。
接下来,我关注了this tutorial。
我最终得到了这段代码:
const auth = await google.auth.getClient({
credentials: require(pathToServiceAccountJSON),
scopes: "https://www.googleapis.com/auth/drive"
});
const drive = await google.drive({ version: "v3", auth });
drive.files
.create({
resource: {
name: filename,
mimeType: "application/vnd.google-apps.folder",
parents: [parentId]
}
})
.then(result => console.log("SUCCESS:", result))
.catch(console.error);
但是,执行它会导致抛出以下错误:
{
...
errors: [{
domain: "global",
reason: "forbidden",
message: "Forbidden"
}]
}
【问题讨论】:
-
你能提供你的整个脚本来复制你的错误吗?当然,请删除您的个人信息。
标签: node.js authentication error-handling google-drive-api service-accounts