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

问题描述

使用完整驱动器范围执行以下命令

Doing the following command with the full drive scope

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

结果

权限不足错误.

尝试从谷歌驱动器与我共享"文件夹中删除文件时.

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.

您需要做的第一件事是运行 about.get:

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",

完成后,您可以执行 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.

然后您可以使用 删除用户对文件的权限权限.删除

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

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

05-18 18:41