C# google drive api更改所有者/转让所有者
我想使用google drive api v2更新google drive中某些文件的权限。 一切正常,文件列表,权限插入。。。。只有权限更新我有问题,但只有当我想改变所有者 有一个名为“transferOwnership”的参数,如果我将其设置为“try it”,则一切正常,但我不知道/无法找到任何方法在我的代码中设置此参数C# google drive api更改所有者/转让所有者,c#,google-drive-api,google-drive-realtime-api,C#,Google Drive Api,Google Drive Realtime Api,我想使用google drive api v2更新google drive中某些文件的权限。 一切正常,文件列表,权限插入。。。。只有权限更新我有问题,但只有当我想改变所有者 有一个名为“transferOwnership”的参数,如果我将其设置为“try it”,则一切正常,但我不知道/无法找到任何方法在我的代码中设置此参数 var permissionresult = UpdatePermission(service, "fileid", "permissionid", "owner");
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;
}
希望有人能帮助我,这是我完成我的应用程序所需要的最后一件事
谢谢
markus您需要初始化一个新的
权限
实例,或者使用现有的实例来修改角色
、类型
和值
字段:
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);
您需要初始化新的
权限
实例,或使用现有实例修改角色
、类型
和值
字段:
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);
我想这就是你想要的:
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;
}
我想这就是你想要的:
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;
}
您只能更改您拥有的文件或文件夹的所有者
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();
希望这有帮助 您只能更改您拥有的文件或文件夹的所有者
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();
希望这有帮助 嗨,谢谢你的回答,但这并没有回答我的问题。嗨,谢谢你的回答,但这并没有回答我的问题。