make folder shared google drive api v3?

…衆ロ難τιáo~ 提交于 2019-12-31 02:43:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!