1

我想使用 google drive api v2 更新 google drive 中某些文件的权限。一切正常,文件列表,权限插入,....只有权限更新我有问题,但只有当我想更改所有者时!

有一个名为“transferOwnership”的参数,如果我在https://developers.google.com/drive/v2/reference/permissions/update上将其设置为 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;
}

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

谢谢马库斯

4

3 回答 3

1

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

Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);
于 2013-08-15T15:22:42.697 回答
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;
}
于 2014-08-04T13:46:10.550 回答
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();

希望这有帮助!

于 2020-03-10T10:56:46.683 回答