I'm building an API that allows users to have access to the list of files hosted on google drive, and I'm reading documentation to see if there are enough resources to make it possible.

My idea is to allow user to update the visibility of a single file. In the documentation this option is marked under the property "shared" with a boolean value.

In the API Reference of "File > Update" method I didn't find a parameter that could let me do this.

In the generic Google Drive interface this option is available through the "Share" option which prompts you a window where you set the visibility to "Private" / "Public on web" / "Whoever has the link".

Am I able to do this with the API?

有帮助吗?

解决方案

I solved it, posting the solution below:

To set a file "sharable" you must set permissions in this api call in this way:

var resource = {
  'value': 'default',
  'type': 'anyone',
  'role': 'reader'
};
var request = gapi.client.drive.permissions.insert({
  'fileId': fileId,
  'resource': resource
}).execute(function() { 
  alert("file set to public")
});

to set the file back to private there is update and delete method. In case of "delete", this is the way to perform it:

  var request = gapi.client.drive.permissions.delete({
    'fileId': fileId,
    'permissionId': 'anyone'
  }).execute(function() { 
    alert("public permissions revoked")
  });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top