'Transferring ownership of the file using Google Drive API
I'm creating a spreadsheet file using google drive api, then pass ownership to another email, $automationEmail in this case. This is how I do it:
$permission = $this->insertPermission($service, $file->id, $automationEmail, 'user', 'owner');
And this is the insertPermission function
function insertPermission($service, $fileId, $value, $type, $role)
{
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress($value);
$newPermission->setType($type);
$newPermission->setRole($role);
if ($role == 'owner') {
$permission = $service->permissions->create($fileId, $newPermission, array('fields' => 'id', 'transferOwnership' => 'true'));
} else {
$permission = $service->permissions->create($fileId, $newPermission);
}
if ($permission) {
return $permission;
}
return NULL;
}
Until now, this used to work perfectly fine. But recently it stopped working and gives me an error: Consent is required to transfer ownership of a file to another user.
For other permissions,like writer or reader, everything works fine. Did anything change in the API that I could not find? I searched for the solution, but seems like noone has had this issue before, or at least I could not find anything. Why did it stop working?
Solution 1:[1]
Issue:
Currently, when transfering file ownership between users who are not part of the same organization, the transfer requires the new owner to accept the invitation.
When the current owner (user #1) sets user #2 as the new owner, an invitation is sent to user #2, and user #1 remains the owner until user #2 accepts it:
You remain the file owner until the pending owner accepts your invitation.
Since this requires the new owner to accept the invitation, the transfer cannot be done programmatically via API, so this method fails for users who don't belong to the same organization.
From Issue Tracker https://issuetracker.google.com/issues/227973724#comment22 :
Following up here, this is the expected behavior as currently Drive does not support the changing of the ownership for items which are owned by gmail.com accounts.
Issue Tracker feature request:
Reference:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
