user1297061
user1297061

Reputation: 1621

Google Drive API change current user's permission from writer to reader

I'm trying to transfer ownership of a file to someone else and change my own permission to read only. What is the correct way to use permission api? I have tried both patch and update and neither seems to work.

The way I did it:

  1. Getting permissionId from getIdForEmail
  2. In the patch body I have {'role': 'reader'} as body but I keep getting 400 error.

Permission 'delete' does work but I need the user to retain reader permission.

Also, is 'me' a valid permissionId?

Upvotes: 1

Views: 514

Answers (1)

Jay Lee
Jay Lee

Reputation: 13528

I was able to achieve this using the following method:

  1. While still owning the file, make sure writersCanShare is true (otherwise you'll transfer ownership, become a writer and be unable to change permissions after that).

  2. Retrieve the current permissions of the file with permissions.list(). You can note the permissionId for yourself here.

  3. If the desired new owner already has rights to the file, perform a permissions.patch() to make them an owner. If they don't already have explicit rights to the file, perform a permissions.insert() to make them the owner.

  4. Now as a writer you can perform a permissions.patch() using your permissionId and setting the role to reader.

  5. Note that after this, calls to permissions.list() will only return the file owner, because readers like yourself can't see the full file permissions.

'me' does not seem to work as a permissionId.

Upvotes: 2

Related Questions