'Consent is required to transfer ownership of a file to another user [Google Drive API]
I have a Google Sheets file shared with 1 user - owner (Gmail account) and 2nd user - writer (google service account like @iam.gserviceaccount.com).
I use this function to copy a table from user 1 by user 2 and make the owner of copied file user 1 again:
$ownerPermission = new Google_Service_Drive_Permission([
'type' => 'user',
'role' => 'owner',
'emailAddress' => '[email protected]'
]);
$requestOwnership = $service->permissions->create($newfileId, $ownerPermission, ['fields' => 'id', 'transferOwnership' => 'true']);
And all works well until yesterday! Now Gooogle Drive API returns error: Consent is required to transfer ownership of a file to another user
How to fix it?
Solution 1:[1]
This seems to be a recent change to the google API. See also https://developers.google.com/drive/api/guides/manage-sharing
I haven't tried this, but it suggests that you should replace transferOwnership=true with role=writer and pendingOwner=true, and then separately update the permissions as [email protected] with role=owner. I don't know how you do that second step from a gmail.com account though.
Solution 2:[2]
This seems to be working as expected as according to this Issue Tracker issue here:
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.
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 | Ian McCulloch |
| Solution 2 |
