3

I have setup a service account to copy a file a user uploads. How do I transfer the ownership to a different email address?

I have:

new_permission = {'value': 'me@example.com', 'type': 'user', 'role': 'owner', 'transferOwnership': True} # also tried "true" and "True"
r = service.permissions().update(fileId=id, permissionId=perm_id, body=new_permission).execute()

No transfer of ownership takes place and the owner continues to be my service account.

EDIT: No errors occur either; it just doesn't change the owner.

EDIT #2: I've also tried via https://developers.google.com/drive/v2/reference/permissions/update with no luck. I receive a 200 response but the owner is still my service account rather than "me@example.com":

{
 "kind": "drive#permission",
 "etag": "\"xxxxxxx/xxxxxxx-x\"",
 "id": "xxxxxxxxxxx",
 "selfLink": "https://www.googleapis.com/drive/v2/files/myfileid/permissions/xxxxxx",
 "name": "myserviceaccount",
 "emailAddress": "myserviceaccount@developer.gserviceaccount.com",
 "domain": "developer.gserviceaccount.com",
 "role": "owner",
 "type": "user"
}

EDIT #3: I've also tried the "patch" method...I get the same result as the "update" method.

user_78361084
  • 3,538
  • 22
  • 85
  • 147
  • It looks like you are using "transferOwnership" as part of the body and not as part of the url parameters as mentioned in the documentation: h ttps://www.googleapis.com/drive/v2/files/{fileId}/permissions/{permissionId}?transferOwnership=true – Gerardo Feb 23 '15 at 22:09
  • transferOwnership is in the "new_permission" dict, where all the other query parameters are. Also, I've tried the "Try It!" section at https://developers.google.com/drive/v2/reference/permissions/update with the same issue occurring...so they must be doing it wrong also? – user_78361084 Feb 24 '15 at 23:47
  • Of course Not, it has to be something you are doing wrong in both places.... if the url parameters are fine, then I'll guess you used the permission Id of your own user and not the permission id of the person to whom you want to transfer the ownership. – Gerardo Feb 26 '15 at 19:17
  • @Gerardo: The permission id I am using is from my service account. When I try to use the permission id for "me@example.com" I get a "403 Forbidden (Insufficient permissions for this file)". (I got the permission id's from developers.google.com/drive/v2/reference/permissions/) – user_78361084 Mar 01 '15 at 17:50

1 Answers1

1

Have you tried using https://developers.google.com/drive/v2/reference/permissions/insert to insert the new owner and then updating the ownership as per your method?

Nabeel
  • 2,272
  • 1
  • 11
  • 14