[英]Share uploaded files with specific user using google Drive API
I am trying to share upload file using google drive API.I following this tutorial我正在尝试使用谷歌驱动器 API 共享上传文件。我遵循本教程
Upload files/folder, List drive file are working fine but I want to add share functionality where file can we share with specific user.上传文件/文件夹,列出驱动器文件工作正常,但我想添加共享功能,我们可以在其中与特定用户共享文件。
I didn't found any solution.我没有找到任何解决方案。 how to share file?
如何共享文件?
If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样? Please think of this as just one of several answers.
请将此视为几个答案之一。
In order to give the permissions for the file, the method of "Permissions: create" in Drive API is used.为了给文件赋予权限,使用Drive API中的“权限:创建”方法。
In this sample script, I prepared the function of createPermissions
for your situation.在这个示例脚本中,我为您的情况准备了
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
});
});
}
When you use this function, please use as follows.使用此功能时,请按如下方式使用。
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);
###
, as writer
and user
.###
,作为writer
和user
。 About the detail information of parameters, please check the official document .If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.