我想使用google drive api v2更新google驱动器中某些文件的权限。 一切正常,文件列表,权限插入,....只有权限更新我有一个问题,但只有我想要更改所有者!
有一个名为“transferOwnership”的参数,如果我在https://developers.google.com/drive/v2/reference/permissions/update上设置“尝试它”以确定一切正常但我不知道/可以找到任何方式如何在我的代码中设置此参数!?
var permissionresult = UpdatePermission(service, "fileid", "permissionid", "owner");
public static Permission UpdatePermission(DriveService service, String fileId,
String permissionId, String newRole)
{
try
{
// First retrieve the permission from the API.
Permission permission = service.Permissions.Get(fileId, permissionId).Execute();
permission.Role = newRole;
return service.Permissions.Update(permission, fileId, permissionId).Execute();
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
return null;
}
希望有人可以帮助我,这就是我需要完成我的应用程序的最后一件事。
感谢 马库斯
答案 0 :(得分:1)
您需要初始化新的Permission
实例或使用现有实例来修改Role
,Type
和Value
字段:
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);
答案 1 :(得分:0)
我认为这就是你想要的:
var permissionresult = UpdatePermission(service, "fileid", "permissionid", "owner");
public static Permission UpdatePermission(DriveService service, String fileId,
String permissionId, String newRole)
{
try
{
// First retrieve the permission from the API.
Permission permission = service.Permissions.Get(fileId, permissionId).Execute();
permission.Role = newRole;
//Call the TransferOwnership property
var updatePermission = service.Permissions.Update(permission, fileId, permissionId);
updatePermission.TransferOwnership = true;
return updatePermission.Execute();
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
return null;
}
答案 2 :(得分:0)
您只能更改所有者,即您拥有的文件或文件夹。
Permission permission = new Permission
{
Role = "owner",
Type = "user",
EmailAddress = "abcnewideal2020@gmail.com"
};
//Call the TransferOwnership property
var updatePermission = service.Permissions.Update(permission, fileId, permissionId);
updatePermission.TransferOwnership = true;
return updatePermission.Execute();
希望有帮助!