I'm trying to change the owner with Google Drive API by updating the permissions:
permissions = drive_api.files().get(fileId=ssId, fields='permissions').execute()['permissions']
[{'displayName': 'account_name',
'emailAddress': 'account_email',
'id': 'id1',
'role': 'writer',
'type': 'user'},
{'displayName': 'api_email',
'emailAddress': 'api_email',
'id': 'id2',
'role': 'owner',
'type': 'user'}]
I take my account permission id:
for permission in permissions:
if permission['emailAddress'] == 'account_email':
permissionId = permission['id']
break
Take the body:
body = drive_api.permissions().get(fileId=ssId, permissionId=permissionId).execute()
{'id': 'id1',
'kind': 'drive#permission',
'role': 'writer',
'type': 'user'}
Change the role:
body['role'] = 'owner'
And do the update:
drive_api.permissions().update(fileId=ssId, permissionId=permissionId, body=body, transferOwnership=True).execute()
But get an error:
The resource body includes fields which are not directly writable
I changed this thing and it started working:
body = {
'id': permissionId,
'role': 'owner',
}
Shame on Google for this horrible Drive API documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.