使用Google Drive API从其他所有者删除文件 [英] Delete a file from different owner with Google Drive API

查看:295
本文介绍了使用Google Drive API从其他所有者删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个小应用程序,与我的组织的不同用户读取共享文件夹,获取文件然后删除它们。



问题是我无法删除不同用户的文件,因为我只能删除我的所有权文件(接收403文件的权限不足)



另一个解决方案I发现是更改文件的所有者,但是我得到了同样的错误。



我使用具有组织的SuperAdmin帐户的本机应用程序oAuth测试它并使用服务帐户,并且它们都不起作用。

我的一段代码试图改变所有权:

  new_permission = {
'value':admin@organization.com,
'type':user,$ b $'role':writer

perm = drive_service.permissions()。insert(fileId = idfield,body = new_permission).execute()
perm ['role'] ='owner'
drive_service .permissions()。更新(fileI d = idfield,permissionId = perm ['id'],transferOwnership = True,body = perm).execute()



我花了几个小时搜索并尝试了我找到的不同解决方案,但没有人工作(例如,)也无法转让文件所有权。



有人有一些想法?现在最好的解决方案包括两个步骤:

    >
  1. 作为管理员帐户,确定每个文件的当前所有者。

  2. 使用委托授权,模拟每个文件的所有者并将所有权转移给管理员帐户。

所有者的电子邮件地址必须使用委托授权,但并不总是在API返回的权限对象中可见。如果有以下任一情况,电子邮件地址将可见:




  • 用户拥有Google+帐户,其个人资料的联系信息部分包含其主要电子邮件地址,并且该电子邮件地址的可见性设置为包含管理员帐户的级别。

  • 该用户位于Google Apps域中,并且该域已在管理控制台中的Google应用程序>联系人>高级设置。


I'm trying to do a small application that reads a shared folder with different users of my organization, get the files and then delete them.

The problem is that I can't delete the file of a different user, because I can only delete files of my ownership (receiving a 403 Insufficient permissions for this file)

Another solution I found is change the owner of the file, but I get the same error.

I test it with a Native Application oAuth with a SuperAdmin account of the organization and with a service account, and none of them works.

A piece of my code trying to change the ownership:

new_permission = {
    'value': "admin@organization.com",
    'type': "user",
    'role': "writer"
}
perm = drive_service.permissions().insert(fileId=idfield, body=new_permission).execute()
perm['role'] = 'owner'
drive_service.permissions().update(fileId=idfield, permissionId=perm['id'], transferOwnership=True, body=perm).execute()

I spend hours searching and trying different solutions I found, but no one works (for example, Transfer ownership of a file fails - even as Super Administrator (Google Drive API, Java)).

Somebody has some idea? Thanks!

解决方案

The best solution right now involves two steps:

  1. As the admin account, determine the current owner for each file.
  2. Using delegated authorization, impersonate the owner of each file and transfer ownership to the admin account.

The email address of the owner is required to use delegated authorization, but isn't always visible in the permissions objects returned by the API. The email address will be visible if either:

  • The user has a Google+ account, their profile's "Contact Information" section includes their primary email address, and the email address's visibility is set to a level that includes the admin account.
  • The user is in a Google Apps domain and the domain has enabled contact sharing in the Admin console under "Google Apps > Contacts > Advanced settings".

这篇关于使用Google Drive API从其他所有者删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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