【发布时间】:2019-12-02 06:43:53
【问题描述】:
我正在尝试使用 google drive API 共享上传文件。我遵循 this 教程
上传文件/文件夹,列出驱动器文件工作正常,但我想添加共享功能,我们可以与特定用户共享文件。
我没有找到任何解决方案。如何共享文件?
【问题讨论】:
标签: javascript google-drive-api
我正在尝试使用 google drive API 共享上传文件。我遵循 this 教程
上传文件/文件夹,列出驱动器文件工作正常,但我想添加共享功能,我们可以与特定用户共享文件。
我没有找到任何解决方案。如何共享文件?
【问题讨论】:
标签: javascript google-drive-api
如果我的理解是正确的,那么这个答案呢?请认为这只是几个答案之一。
为了给文件赋予权限,使用Drive API中的“Permissions:create”方法。
在这个示例脚本中,我为您的情况准备了createPermissions 的功能。
function createPermissions(fileId, body) {
gapi.client.load('drive', 'v3', function() {
gapi.client.drive.permissions.create({
fileId: fileId,
resource: body,
})
.then(function(res) {
console.log(res)
// do something
})
.catch(function(err) {
console.log(err)
// do something
});
});
}
当您使用此功能时,请按如下方式使用。
const fileId = "###"; // Please set the file ID.
const body = {
role: "writer",
type: "user",
emailAddress: "###" // Please set the email address of user that you want to share.
};
createPermissions(fileId, body);
###,分别为writer 和user。详细参数请查看the official document。如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
【讨论】:
drive.file的范围是Per-file access to files created or opened by the app.。那么尝试使用https://www.googleapis.com/auth/drive 怎么样?虽然我很想支持你,但很遗憾,我不确定你的实际情况,所以当这没有解决你的新问题时,你可以通过包含详细信息将它作为新问题发布吗?这样,它将帮助包括我在内的用户思考您的问题。