I just started using Google Drive API and turns out I can't migrate ownership of the created file. I uploaded a file to drive from a service account, then gave myself the "writer" permission and tried to update myself to an owner, as it is written in api docs.
media = MediaFileUpload(filename, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
file = driveService.files().create(media_body=media, fields='id').execute()
access = driveService.permissions().create(
fileId = file['id'],
body = {'type': 'user', 'role': 'writer', 'emailAddress': my_email},
fields = 'id'
).execute()
update = driveService.permissions().update(fileId=file.get('id'),
permissionId=access.get('id'),
transferOwnership=True,
body = {'role': 'owner', 'emailAddress': my_email }).execute()
--------------------------------------------------------------------------
HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/file_id/permissions/permission_id?transferOwnership=true&alt=json returned "The resource body includes fields which are not directly writable.">
Update: issue was fixed by removing an "emailAddress" parameter, but then I got new error:
HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/fileId/permissions/permissionId?transferOwnership=true&alt=json returned "The user does not have sufficient permissions for this file.">
Another update: I reauploaded credetials file and it fixed the second error.