【发布时间】:2021-08-04 21:40:52
【问题描述】:
我能够使用服务帐户成功地将文件上传到 Google 云端硬盘共享云端硬盘(不是 “我的云端硬盘” 文件夹,这是不同的)。但是当我尝试删除文件时,我得到了一个The user does not have sufficient permissions for this file. [403]
请注意,在我的代码中,我设置了 request.SupportsAllDrives = true; 标志以允许它访问共享驱动器。
我检查了服务帐户的权限 ID 和文件的权限 ID,不出所料,它们是相同的,因为服务帐户是首先将文件放在那里的人。
对出了什么问题有任何想法吗?
/// <summary>
/// Permanently delete a file, skipping the trash.
/// </summary>
/// <param name="service">Drive API service instance.</param>
/// <param name="fileId">ID of the file to delete.</param>
public async Task<string> DeleteDriveFile(DriveService service, string fileId)
{
// get the user's permission id from Drive
var getRequest = service.About.Get();
getRequest.Fields = "*";
var getResponse = await getRequest.ExecuteAsync().ConfigureAwait(true);
string userPermissionId = getResponse.User.PermissionId;
Debug.Print($"UserPermissionID: {userPermissionId}");
var responseFile = service.Permissions.Get(fileId, userPermissionId);
Debug.Print($"FilePermissionID: {responseFile.PermissionId}");
string response = "";
try
{
var request = service.Files.Delete(fileId);
request.SupportsAllDrives = true;
response = await request.ExecuteAsync().ConfigureAwait(false);
}
catch (Exception e)
{
Debug.WriteLine("Delete File Error: " + e.Message);
}
return response;
}
写入输出控制台的内容:
UserPermissionID: 0243088xxxxxx3009857
FilePermissionID: 0243088xxxxxx3009857
The thread 0x1398 has exited with code 0 (0x0).
Exception thrown: 'Google.GoogleApiException' in System.Private.CoreLib.dll
Delete File Error: Google.Apis.Requests.RequestError
The user does not have sufficient permissions for this file. [403]
Errors [
Message[The user does not have sufficient permissions for this file.] Location[ - ] Reason[insufficientFilePermissions] Domain[global]
]
【问题讨论】:
-
你解决了吗?
标签: c# .net permissions drive