[英]How to change the owner with Google Drive API v3 in Python?
I'm trying to change the owner with Google Drive API by updating the permissions:我正在尝试通过更新权限使用 Google Drive API 更改所有者:
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:我使用我的帐户权限 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这个可怕的 Drive API 文档让 Google 感到羞耻
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.