如何以编程方式从“与我共享”中删除文件,在Google云端硬碟中 [英] How to programmatically remove a file from "share with me" in Google drive

查看:129
本文介绍了如何以编程方式从“与我共享”中删除文件,在Google云端硬碟中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在完整的驱动器范围内执行以下命令

Doing the following command with the full drive scope

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

结果


权限不足错误。

insufficient permission error.

尝试从Google驱动器与我共享文件夹中删除文件时。

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 don't own?

推荐答案

问题是所涉及的用户不拥有该文件。经过大量的挖掘,我意识到您想要做的是删除有关文件的用户权限。

The problem is that the user in question doesn't own the file. After a lot of digging I realised that what you want to do is to remove the permissions for the user on the file in question.

您需要做的第一件事是运行关于当前用户的

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

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

这将为您提供该用户的权限ID

This will give you the permission id of that user


permissionId: 060305882255734372,

"permissionId": "060305882255734372",

一旦完成,您就可以这样做该用户文件上的 permissions.get

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();

响应

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

哪个会给您文件的权限ID有问题的用户。

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

然后,您可以使用 permission.delete

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

这篇关于如何以编程方式从“与我共享”中删除文件,在Google云端硬碟中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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