Reputation: 5
I am attempting to create a google spreadsheet using the google sheets api and then update the permissions of the sheet file to have a new owner using the Google Drive API.
I am getting the following error even though I am passing the value as per the doc:
An error occurred while creating permission: <HttpError 400 when requesting https://www.googleapis.com/drive/v2/files/1xVPxNHQmbO2RSbzbTg7K3qLa8fURP3S_xkIStMVIpK8/permissions?alt=json returned "Permission value field required". Details: "[{'domain': 'global', 'reason': 'required', 'message': 'Permission value field required', 'locationType': 'other', 'location': 'permission.value'}]">
I am using the below code snippet taken from google docs here:
def driveService(fileID, email):
drive_service = build('drive', 'v2')
insert_permission(drive_service, fileID, email, "user", "owner")
def insert_permission(service, file_id, email, perm_type, role):
"""Insert a new permission.
Args:
service: Drive API service instance.
file_id: ID of the file to insert permission for.
value: User or group e-mail address, domain name or None for 'default'
type.
perm_type: The value 'user', 'group', 'domain' or 'default'.
role: The value 'owner', 'writer' or 'reader'.
Returns:
The inserted permission if successful, None otherwise.
"""
new_permission = {
'type': perm_type,
'role': role,
'value': email
}
try:
return service.permissions().insert(
fileId=file_id, body=new_permission).execute()
except errors.HttpError as error:
print('An error occurred while creating permission: %s' % error)
return None
Upvotes: 0
Views: 1604
Reputation: 117046
Try this let me know if it doesnt work i will make a full sample tomrrow.
permission1 = {
'type': 'user',
'role': 'writer',
'emailAddress': '###', # Email of Google account.
}
service.permissions().create(fileId=fileId, body=permission1).execute()
permission2 = {
'type': 'anyone',
'role': 'writer',
}
service.permissions().create(fileId=fileId, body=permission2).execute()
Upvotes: 0