谷歌驱动api变更所有者/转让所有者

本文关键字:所有者 api 谷歌 | 更新日期: 2023-09-27 18:27:35

我想使用谷歌驱动器api v2更新谷歌驱动器中一些文件的权限。一切正常,文件列表,权限插入。。。。只有在权限更新的情况下,我才有问题,但前提是我想更改所有者!

有一个名为"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;
}

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

谢谢markus

谷歌驱动api变更所有者/转让所有者

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

Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);

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

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();

希望得到帮助!

我想这就是你想要的:

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