如何使用Python中的Google Drive API v3更改所有者? [英] How to change the owner with Google Drive API v3 in Python?

查看:140
本文介绍了如何使用Python中的Google Drive API v3更改所有者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过更新权限来更改Google Drive API的所有者:

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'}]

我使用我的帐户许可ID:

I take my account permission id:

for permission in permissions:
  if permission['emailAddress'] == 'account_email':
    permissionId = permission['id']
    break

身体:

body = drive_api.permissions().get(fileId=ssId, permissionId=permissionId).execute()

{'id': 'id1',
 'kind': 'drive#permission',
 'role': 'writer',
 'type': 'user'}

更改角色:

body['role'] = 'owner'

并进行更新:

drive_api.permissions().update(fileId=ssId, permissionId=permissionId, body=body, transferOwnership=True).execute()

但是出现错误:

资源主体包含不可直接写的字段

The resource body includes fields which are not directly writable

推荐答案

我更改了此方法,它开始起作用:

I changed this thing and it started working:

body = {
    'id': permissionId,
    'role': 'owner',
}

为此可怕的Drive API文档在Google上感到羞耻

这篇关于如何使用Python中的Google Drive API v3更改所有者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆