My code below using Google Drive API v3 to transfer ownership from one user to another in the same domain is throwing this exception. I am using Service Account with domain-wide permissions for authorization piece.
string FileID = "xxxxxxxxxxxxxxxxxxx";
var getRequest1 = OwnerDrive.Files.Get(FileID);
getRequest1.Fields = "owners,name,parents,mimeType,permissions";
var afile = getRequest1.Execute();
foreach (var perm in afile.Permissions)
{
Console.WriteLine(perm.EmailAddress + " : " +
perm.DisplayName + " : " + perm.Role + " : " + perm.Id);
}
// I manually note down the permissionID of the current owner as
"14016095883385444520"
//Set New owner
Permission p = new Permission();
p.Role = "owner";
p.Type = "user";
p.EmailAddress = "newowner@xyz.com";
var updateRequest = OwnerDrive.Permissions.Update(p, FileID,
"14016095883385444520");
updateRequest.TransferOwnership = true;
updateRequest.Execute();
The error\exception throw is this:
"Message[The resource body includes fields which are not directly writable.] Location[ - ] Reason[fieldNotWritable] Domain[global]".
The new drive v3 API says to use Permissions.Update and pass it permissionID which I am doing (although manually). What am I missing here ? Any help is greatly appreciated.