问题
I can make a folder using this code
var request = gapi.client.request({
'path': '/drive/v3/files/',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
//'Authorization': 'Bearer ' + token
},
'body':{
"name" : "copy",
"mimeType" : "application/vnd.google-apps.folder",
}
});
request.execute(function(resp) {
console.log(resp);
//document.getElementById("info").innerHTML = "Created folder: " + resp.title;
});
but I cant figure out for the life of me how to make the folder shared to all, I seen in the documentation to put type:anyone but I cant figure out how to do it in the code, thank you for your time
回答1:
You create a permission for a file or folder with this REST function:
POST https://www.googleapis.com/drive/v3/files/fileId/permissions
So you can do:
var fileId = File Id;
var request = gapi.client.request({
'path': '/drive/v3/files/' + fileId + '/permissions',
'method': 'POST',
'headers': {
'Content-Type': 'application/json'
//'Authorization': 'Bearer ' + token
},
'body':{
'role': 'reader', // owner, writer, commenter
'type': 'anyone'
}
});
If it's successful, it'll give you a Permissions resource as a result:
{
kind: "drive#permission",
id: Unique identifier,
type: string,
emailAddress: string,
domain: string,
role: string,
allowFileDiscovery: boolean,
displayName: string,
photoLink: string
}
I give you links to the reference, but I haven't found any example there:
- Share file/folder
- Create permission
- Permission resource
来源:https://stackoverflow.com/questions/36538269/make-folder-shared-google-drive-api-v3