简体   繁体   English

如何在 Python 中使用 Google Drive API v3 更改所有者?

[英]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.

相关问题 如何使用 Python (FLASK) 实现 Google Drive V3 API - How to Implement Google Drive V3 API with Python (FLASK) 如何使用Google Drive API v3上传到Python中的共享驱动器? - How do I upload to a shared drive in Python with Google Drive API v3? 如何使用 Python 和 Drive API v3 将文件上传到 Google Drive - How to upload a file to Google Drive using Python and the Drive API v3 如何使用 Python 和 Drive API v3 从 Google Drive 下载文件 - How to download a file from Google Drive using Python and the Drive API v3 Google Drive API v3 更改文件权限并获取可公开共享的链接 (Python) - Google Drive API v3 Change File Permissions and Get Publicly Shareable Link (Python) 在Python中覆盖Google Drive API v3 Argparse - Overwriting Google Drive API v3 Argparse in Python Google Client API v3 - 使用 Python 更新驱动器上的文件 - Google Client API v3 - update a file on drive using Python 通过python的Google Drive api v3文件上传错误 - Google Drive api v3 file upload errors via python 如何通过Python API使用Google Drive v3 API限制编辑者共享电子表格? - How to use Google Drive v3 API via Python API to restrict editors from sharing a spreadsheet? 如何使用 Python 将文件插入/上传到 Google Drive API v3 中的特定文件夹 - How can I insert/upload files to a specific folder in Google Drive API v3 using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM