問題描述
我正在嘗試做一個小型應用程序,它可以讀取與我組織的不同用戶共享的文件夾,獲取文件然后刪除它們.
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.
問題是我無法刪除其他用戶的文件,因為我只能刪除我擁有的文件(收到 403 Insufficient permissions for this file)
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.
我使用本機應用程序 oAuth 以及組織的 SuperAdmin 帳戶和服務帳戶對其進行測試,但它們都不起作用.
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()
我花了數小時搜索和嘗試找到的不同解決方案,但沒有一個有效(例如,文件所有權轉移失敗 - 即使作為超級管理員(Google Drive API,Java)).
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:
- 作為管理員帳戶,確定每個文件的當前所有者.
- 使用委托授權,模擬每個文件的所有者并將所有權轉讓給管理員帳戶.
- As the admin account, determine the current owner for each file.
- Using delegated authorization, impersonate the owner of each file and transfer ownership to the admin account.
所有者的電子郵件地址需要使用委托授權,但在 API 返回的權限對象中并不總是可見.如果出現以下任一情況,電子郵件地址將可見:
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:
- 用戶擁有 Google+ 帳戶,其個人資料的聯系信息"部分包含他們的主要電子郵件地址,并且電子郵件地址的可見性設置為包含管理員帳戶的級別.
- 用戶位于 Google Apps 域中,并且該域已在管理控制臺中的Google Apps > 聯系人 > 高級設置"下啟用聯系人共享.
這篇關于使用 Google Drive API 從其他所有者刪除文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!