Google Drive API转让所有权 [英] Google Drive API Transfer ownership

查看:60
本文介绍了Google Drive API转让所有权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

语言:Python库版本:oauth2client(1.4.6)apiclient(1.0.2)

Language: Python Libs version: oauth2client (1.4.6) apiclient (1.0.2)

脚本任务:

1-搜索由帐户"B"与帐户"A"共享的文件

1 - Search for files shared with account "A" by account "B"

param['pageToken'] = page_token
param['maxResults'] = 1000
param['q'] = "not '%s' in owners and trashed = false" % (account_A_email)
files = service.files().list(**param).execute()

2-使用"SignedJwtAssertionCredentials"模拟为帐户"B",并将帐户"A"设置为所有者

2 - Impersonate as account "B" using "SignedJwtAssertionCredentials" and set account "A" as owner

new_permission = {}
new_permission['value'] = account_A_email
new_permission['type'] = 'user'
new_permission['role'] = 'owner'
service.permissions().insert(fileId=file_id, body=new_permission).execute()
# Note: I have tried service.permissions().update() but it did not work

问题:

将新权限应用于任何文件后,该文件将显示在帐户"A"根文件夹以及原始位置上.此行为类似于云端硬盘用户界面中的添加到我的云端硬盘".

Once the new permission applied on any file, the file appears on account "A" root folder as well as the original location. This behavior is similar to "Add to my Drive" in the Drive UI.

是否知道如何停止添加到我的云端硬盘"行为?

Any idea how to stop the "Add to my Drive" behavior?

谢谢,

推荐答案

好吧,我做了以下工作,经过几个小时和几杯咖啡后,它才起作用:)

Ok I did the following and it worked after couple of hours and loads of cups of coffee :)

而不是使用导致问题的原因":

Instead of using "which causes the issue":

service.permissions().insert(fileId=file_id, body=new_permission).execute()

使用以下内容:

param_perm['value'] = new_owner
param_perm['type'] = 'user'
param_perm['role'] = 'owner'
service.permissions().update(fileId=file_id,
                             permissionId=perm_id,
                             body=param_perm,
                             transferOwnership=True).execute()

与之前的试用版不同的是,permissionId是新所有者"的许可ID,不是先前的所有者.

What changed from my previous trial is the permissionId which is the "new owner" permission id not the previous owner.

这篇关于Google Drive API转让所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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