0

I want to transfer ownership of a google sheet that I created using my service account to my personal account using Python.

from google.oauth2 import service_account
from googleapiclient.discovery import build

creds = service_account.Credentials.from_service_account_file('credentials.json')

service = build('drive', 'v3', credentials=creds)

permission = {
    'type': 'user',
    'role': 'writer',
    'transferOwnership': 'true',
    'pendingOwner': 'true',
    'emailAddress': new_owner_email
}

service.permissions().create(
    fileId=sheet_id,
    body=permission,
    transferOwnership=True
).execute()

I get below error.

HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/1X7O2jv-KDqZhvjTW3Dif1tuyvPA8O15Ck3e4foAf7-Y/permissions?transferOwnership=true&alt=json returned "The transferOwnership parameter must be enabled when the permission role is 'owner'.". Details: "[{'message': "The transferOwnership parameter must be enabled when the permission role is 'owner'.", 'domain': 'global', 'reason': 'forbidden', 'location': 'transferOwnership', 'locationType': 'parameter'}]">

What do I change to make my personal account as the owner of my google sheet?

Mohit Aswani
  • 185
  • 1
  • 7
  • Your sitution might be related to this thread? https://stackoverflow.com/q/75935222 – Tanaike Apr 05 '23 at 13:37
  • Tanaike's thread has the answer, but to be more specific, your error is caused by the `'transferOwnership':'true'` part. According to [the docs](https://developers.google.com/drive/api/guides/manage-sharing#transfer-consumer-account), `pendingOwner` is set by the *current owner* to offer ownership of the file, and `transferOwnership` is set by the *recipient* to accept the file. You're trying to set both as the owner, which won't work. Also, if the permission already exists you'll have to use [update](https://developers.google.com/drive/api/v3/reference/permissions/update). – Daniel Apr 05 '23 at 20:50

0 Answers0