【发布时间】:2020-07-23 14:22:06
【问题描述】:
我刚开始使用 Google Drive API,结果发现我无法迁移所创建文件的所有权。 我从服务帐户上传了一个文件以驱动,然后给自己“作者”权限并尝试将自己更新为所有者,因为它是在 api 文档中编写的。
media = MediaFileUpload(filename, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
file = driveService.files().create(media_body=media, fields='id').execute()
access = driveService.permissions().create(
fileId = file['id'],
body = {'type': 'user', 'role': 'writer', 'emailAddress': my_email},
fields = 'id'
).execute()
update = driveService.permissions().update(fileId=file.get('id'),
permissionId=access.get('id'),
transferOwnership=True,
body = {'role': 'owner', 'emailAddress': my_email }).execute()
--------------------------------------------------------------------------
HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/file_id/permissions/permission_id?transferOwnership=true&alt=json returned "The resource body includes fields which are not directly writable.">
更新: 问题已通过删除“emailAddress”参数得到修复,但随后出现新错误:
HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/fileId/permissions/permissionId?transferOwnership=true&alt=json returned "The user does not have sufficient permissions for this file.">
另一个更新:我重新上传了凭证文件并修复了第二个错误。
【问题讨论】:
-
太棒了!你应该接受你的问题的答案。检查what-to-do-when-someone-answers。
标签: python google-api google-drive-api google-api-client