How to do that? Should I use Google Docs ACL instead and how to configure such ACL?
Asked
Active
Viewed 9,508 times
4 Answers
20
you have to set following parameters :
private Permission insertPermission(Drive service, String fileId) throws Exception{
Permission newPermission = new Permission();
newPermission.setType("anyone");
newPermission.setRole("reader");
newPermission.setValue("");
newPermission.setWithLink(true);
return service.permissions().insert(fileId, newPermission).execute();
}

maales
- 201
- 2
- 7
-
Then you can get the sharing link from the field "webContentLink" – agirardello Aug 19 '14 at 22:11
-
I have written a step by step guide here: http://stackoverflow.com/questions/18917828/google-drive-sdk-change-item-sharing-permissions/27990794#27990794 – Simon Jan 16 '15 at 19:00
4
Use this method to make your file visible to anyone:
private static Permission insertPermission(Drive service, String fileId) throws IOException
{
Permission newPermission = new Permission();
newPermission.setType("anyone");
newPermission.setRole("reader");
return service.permissions().insert(fileId, newPermission).execute();
}
More details here.

Dmytro Danylyk
- 19,684
- 11
- 62
- 68
-
1That makes it publicly available and allows anyone to find it. "Anyone with the link" does not let people find it. Big difference. – Johann Mar 27 '13 at 18:43
-
Actually, I just tried this. When I look at the file with the Drive app on my Android it says "Public on the web (with link) Anyone who has the link". This appears to be what the user wanted. – charles young Jun 26 '13 at 21:00
-
For sake of completeness, if you use "anyone" and "reader" you can use the Google.Apis.Drive.v2.Data.File.WebContentLink (available from the service.Files.Insert operation) as a link to allow anyone to download the file. – charles young Jun 27 '13 at 23:07
1
You have to use the Documents List API to manage sharing. Please check the docs at https://developers.google.com/google-apps/documents-list/#managing_sharing_permissions_of_resources_via_access_control_lists_acls

Claudio Cherubino
- 14,896
- 1
- 35
- 42
0
For Google Drive API V3, use this method to make your file visible to anyone:
private Permission InsertAnyonePermissionToDownload(Google.Apis.Drive.v3.DriveService service, String fileId)
{
Permission newPermission = new Permission();
newPermission.Type = "anyone";
newPermission.Role = "reader";
return service.Permissions.Create(newPermission, fileId).Execute();
}
-
1Welcome to SO, Fabricio H. da Rocha! Code-only answers are discouraged here, as they provide no insight into how the problem was solved. Please update your solution with an explanation of how your code solves the problem at hand :) – Joel Nov 08 '18 at 17:21