Would really appreciate some advice while working with the Permissions part of the Google Team Drive API: https://developers.google.com/drive/v3/reference/permissions
I am currently writing a piece of code which will Create a team drive, create some files (mimetype folder) to the teamdrive by the ID and then adding a user to the Team Drive as a group.
The code is successfully creating a Team Drive and Folders for each using the API, however, when I add a User to the team drive my response is completely different, for example:
def build_google_teamdrive(drive_name):
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v3', http=http)
team_drive_metadata = {'name': drive_name, "colorRgb": "#004e37"}
request_id = str(uuid.uuid4())
response = service.teamdrives().create(body=team_drive_metadata, requestId=request_id).execute()
logger.info('Creating Team Drive for: {}'.format(drive_name))
print(response)
return response
This returns a expected response of:
{u'kind': u'drive#teamDrive', u'id': u'0AFlsLbuvuChJUk9PVA', u'name': u'TeamDriveName'}
This confirms that the code has run expected, same with the .files().
Now when I try to do add a member (group) to a Team Drive, I am getting something totally different:
def test_insert():
viewer_group = 'some_user@test.domain.co.uk'
drive_unique_id = '0BKk5OjdX66ooUk9PVA'
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v3', http=http)
resource = {
"role": "reader",
"type": "group",
"emailAddress": viewer_group
}
response = service.permissions().create(fileId=drive_unique_id, body=resource, supportsTeamDrives=True, sendNotificationEmail=False)
print(response)
return response
This returns the response:
<googleapiclient.http.HttpRequest object at 0x104e741d0>
When using the Permissions Insert API : The response I am expecting was:
{"kind": "drive#permission","id": "00723864391275245674","type": "group","role": "reader"}
If I could get any help regarding this problem I would be really appreciative as I am really baffled how it is not working.
Thanks, PyJordan
Looking at the code it is quite clear why the response did not return as expected, please look here:
response = service.teamdrives().create(body=team_drive_metadata, requestId=request_id).execute()
As you can see at the end of the response, you have wrote:
.execute()
The fix is simple, in your code you have wrote:
response = service.permissions().create(fileId=drive_unique_id, body=resource, supportsTeamDrives=True, sendNotificationEmail=False)
I will now fix this for you:
response = service.permissions().create(fileId=drive_unique_id, body=resource, supportsTeamDrives=True, sendNotificationEmail=False).execute()
Hope this helps and goodluck.
VS