简体   繁体   English

从与我共享的文件夹中完全删除文件

[英]Delete a file completely from shared with me folder

I am trying to delete a file which is shared with me using Google Drive API but since I'm not the owner of the file I'm getting a permission error. 我正在尝试删除使用Google Drive API与我共享的文件,但是由于我不是该文件的所有者,因此出现权限错误。 I looked the on the web and find this solution . 我在网上查看并找到了解决方案 I implemented the solution as below: 我实现了以下解决方案:

About about = service.about().get().execute();
String rootId = about.getRootFolderId();
service.parents().delete(fileId, rootId).execute();

However, I cannot delete the file with this code. 但是,我无法使用此代码删除文件。 It doesn't give any error but I can still see the file in my google drive. 它没有给出任何错误,但我仍然可以在Google驱动器中看到该文件。

PS: I checked the fileId parameter and it's referencing to the correct file. PS:我检查了fileId参数,它引用了正确的文件。

Sorry I don't Know java so couldn't provide any code sample. 抱歉,我不知道Java,所以无法提供任何代码示例。

So In Google Drive API V3 you can no longer get the root folder Id by getRootFolderId method using About Resource. 因此,在Google Drive API V3中,您不再可以使用About Resource通过getRootFolderId方法获取根文件夹ID。

Instead you need to use file.get method, use root (instead of your file Id) as the fileId and request additional field id (passing ?fields=id ) to get the rootFolderId. 相反,您需要使用file.get方法,使用root (而不是您的文件ID)作为fileId并请求其他字段id (传递?fields=id )以获取rootFolderId。

In the Drive API V3 they have stopped returning full resource by default. 在Drive API V3中,默认情况下,它们已停止返回完整资源。 So be careful if you use any code related to V2. 因此,如果使用任何与V2相关的代码,请务必小心。

Check out the Fields Section in google drives api official migration document. 在Google Drives API官方迁移文档中查看“ 字段”部分。

Hope this helps. 希望这可以帮助。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM