1

I am using PyDrive to create a Google Sheets file on a Google Shared Drive, the below code snippet successfully creates the file in my shared drive folder:

f = gd.CreateFile(
            {'title': name, 'mimeType': 'application/vnd.google-apps.spreadsheet', 'parents': [{'teamDriveId': '1234', 'id': '1234'}]})
        f.Upload(param={'supportsTeamDrives': True})

On adding the file, I am also trying to set permissions for an email address to gain write access to the file as below:

f.InsertPermission({'type': 'user', 'value': 'myemail@email.com', 'role': 'writer'})

On attempting to add the permissions, I receive the below error:

<HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_id_here/permissions?alt=json returned "File not found: file_id_here">

I have checked and the file id appears to be the same as the one that has been created.

I assumed that it wouldn't be any authorisation issue if I am able to create the file? Any suggestions would be very much appreciated.

Thanks

Chris
  • 647
  • 1
  • 8
  • 32

2 Answers2

2

I have found it appears to be an issue with no entry for 'supportsTeamDrives' in the PyDrive's files.py file in the InsertPermission function.

I added the 'supportsTeamDrives' parameter into the code at line 325 as follows and it now appears to work:

permission = self.auth.service.permissions().insert(
                fileId=file_id, body=new_permission, supportsTeamDrives=True).execute(http=self.http)
Chris
  • 647
  • 1
  • 8
  • 32
1

The best way I found using pyDrive was doing this:

file = gd.CreateFile({'title': 'filename', 'parents': [{'teamDriveId': '<your teamDriveId>', 'id': '<file id>'}]})
file.Upload(param={'supportsTeamDrives': True})
# here we can use the pydrive object to update.
new_permission = {
    'id': 'anyoneWithLink',
    'type': 'anyone',
    'value': 'anyoneWithLink',
    'withLink': True,
    'role': 'reader'
}
permission = file.auth.service.permissions().insert(
    fileId=file['id'], body=new_permission, supportsTeamDrives=True).execute(http=file.http)
Rafael
  • 433
  • 6
  • 12