Drive SDK - Change inventory permissions

in accordance with the permissions for sharing SDK files for the Google Drive and https://developers.google.com/drive/v2/reference/permissions I want to change the contents of the entire folder that is viewable (the folder contains only images, and I show them on your page using <img alt='' src='https://drive.google.com/uc?export=view&id="fileID"'/> )

so i try to use this code

 PermissionList permissions = Google_DriveService.Permissions.List(fileId).Fetch(); var filePermissions = permissions.Items; Permission permission = Google_DriveService.Permissions.Get(fileId, filePermissions[0].Id).Fetch(); permission.Role = "reader"; permission.Value = "me"; permission.Type = "anyone"; permission.WithLink = true; var updated = Google_DriveService.Permissions.Update(permission, fileId, filePermissions[0].Id).Fetch(); 

but i get an error

 Google.Apis.Requests.RequestError Invalid permission type specified [400] Errors [ Message[Invalid permission type specified] Location[ - ] Reason[invalid] Domain[global] ] 

what am I doing wrong?

+1
source share
3 answers

You cannot change permission types with update requests, insert a new permission, or delete existing ones. You should also not use me as a principal associated with any resolution. Any permissions do not set value attributes.

+2
source

Tony's answer is correct, and here is an addon to his instructions if someone else wants to check it out. Please note that I did not write code for this due to time limits, but I tested it using the Google APIs provided on the Google Drive Google webpage. I checked this by doing the following:

drive id

Go to the insert permission page here - Tony was right, you are not deleting the existing permission, but instead you are adding permission to this: https://developers.google.com/drive/v2/reference/permissions/insert

  1. In the API browser, enter "role" as "reader" and "type" as "someone."

  2. Go to your drive: https://drive.google.com/drive/#my-drive and you will see that the file is now open - if you hover over the green link icon in the screenshot below, it will tell you that now he is divided.

Drive shared

You can also copy the link for the document and paste it into incognito mode in Chrome to check if you can access the version of the document for reading in incognito mode, and it should work.

Additionally:

The code should not be too complicated, here it is:

  Permission newPermission = new Permission(); newPermission.setType("anyone"); newPermission.setRole("reader"); try { return service.permissions().insert(fileId, newPermission).execute(); } catch (IOException e) { System.out.println("An error occurred: " + e); } 
+3
source

Source: https://habr.com/ru/post/918757/


All Articles