- You want to share the files in Google Drive using Drive API with Javascript.
- You have already been able to get and put for the files on Google Drive using Drive API.
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.
Sample script:
In this sample script, I prepared the function of createPermissions
for your situation.
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);
- When you use this script, please prepare the file ID of the file you want to share.
- At above script, the file is shared with the user, which has the email address of
###
, as writer
and user
. About the detail information of parameters, please check the official document.
Note:
- Unfortunately, in your actual situation, I'm not sure where you want to use the above sample script in your script. So please add it to your script.
Reference:
If I misunderstood your question and this was not the direction you want, I apologize.