Google Drive API更改所有者/转让所有者

问题描述 投票:1回答:3

我想使用Google Drive API v2更新Google Drive中某些文件的权限。一切正常,文件列表,权限插入,.....仅在权限更新的情况下,我有问题,但仅当我想更改所有者时!

[有一个名为“ transferOwnership”的参数,如果我在https://developers.google.com/drive/v2/reference/permissions/update上将其设置为“ try it”为true,则一切正常,但我不知道/可以找到任何方法在我的代码中设置此参数!

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;
}

希望有人可以帮助我,这就是我完成我的应用程序所需要的最后一件事。

谢谢马库斯

c# google-drive-api google-drive-realtime-api
3个回答
1
投票

您需要初始化一个新的Permission实例或使用现有实例来修改RoleTypeValue字段:

Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "[email protected]";
service.Permissions.Update(p, fileId, permissionId);

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;
}

0
投票

您仅更改所有者所拥有的文件或文件夹。

Permission permission = new Permission
            {
                Role = "owner",
                Type = "user",
                EmailAddress = "[email protected]"
            };

            //Call the TransferOwnership property
            var updatePermission = service.Permissions.Update(permission, fileId, permissionId);
            updatePermission.TransferOwnership = true;
            return updatePermission.Execute();

希望获得帮助!

© www.soinside.com 2019 - 2024. All rights reserved.