Reputation: 1223
I don't seem to find many articles on this. The tutorial from Google only shows creating folders in a regular Google Drive folder.
Below is my function and it fails with oogleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "File not found: myteamdrivefolderid.". Details: "File not found: myteamdrivefolderid.">
My app is a Python desktop app and has already been authorized to have full Drive read/write scope.
def create_folder(service, name, parent_id=None, **kwargs):
# Create a folder on Drive, returns the newely created folders ID
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['teamDriveId'] = kwargs['teamDriveId']
folder = service.files().create(body=body).execute()
return folder['id']
Upvotes: 2
Views: 276
Reputation: 201378
I believe your goal and situation as follows.
supportsAllDrives
to the query parameter.teamDriveId
is deprecated. Please use driveId
. RefWhen above points are reflected to your script, it becomes as follows.
body = {
'name': name,
'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
body['driveId'] = kwargs['teamDriveId'] # Modified
folder = service.files().create(body=body, supportsAllDrives=True).execute() # Modified
return folder['id']
Upvotes: 2