How to programmticly remove a file from “share wtih me” in Google drive

≯℡__Kan透↙ 提交于 2019-12-17 21:12:41

问题


Doing the following command with the full drive scope

var request = service.Files.Delete(fileId);

results in

insufficient permission error.

When trying to delete a file from google drive "Shared with me" folder.

How do you delete a file from shared with me when the user that is logged in does not actually have access to delete a file they dont own.


回答1:


The problem is that the user in question doesnt own the file. After a lot of digging a relised what you want to do is remove the permissions for the user on the file.

The first thing you need to do is run an about.get on the current user

return service.About.Get().Execute();

This will give you the permission id of that user

"permissionId": "060305882255734372",

Once that is done you can then do a permissions.get on the file for that user.

var response = service.Permissions.Get(fileId, permissionId).Execute();

Response

{
 "kind": "drive#permission",
 "id": "06030588225573437",
 "type": "user",
 "role": "writer"
}

which will give you the permission id on the file for the user in question.

Then you can delete the permission on the file for the user using permission.delete

var response = service.Permissions.Delete(fileId, permissionId).Execute();


来源:https://stackoverflow.com/questions/56770881/how-to-programmticly-remove-a-file-from-share-wtih-me-in-google-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!