1

I want to update the permission of some files in google drive using google drive api v2. everything works fine, file list, permission insert, .... only with permission update i have a problem but only if i want to change the owner!

There is a parameter called "transferOwnership", if i set this on https://developers.google.com/drive/v2/reference/permissions/update "try it" to true everything works fine but i dont know / can finde any way how to set this parameter in my code!?

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

Hope someone can help me, thats the last thing i need to complete my app.

thanks markus

Kara
  • 6,115
  • 16
  • 50
  • 57

3 Answers3

1

You need to init a new Permission instance or use the existing to modify the Role, Type and Value fields:

Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.Value = "jbd@google.com";
service.Permissions.Update(p, fileId, permissionId);
Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
1

You only change owner the files or folders you own.

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

Hope this help!

Datusa
  • 101
  • 1
  • 3
0

I think this is what you wanted:

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;
}
Nick Prozee
  • 2,823
  • 4
  • 22
  • 49