2

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']

1 Answer 1

2

I believe your goal and situation as follows.

  • You want to create new folder in the shared Drive using googleapis for python.
  • You have the permission for creating new folder in the shared Drive.
  • You have already been able to use Drive API.

Modification points:

  • In this case, please add supportsAllDrives to the query parameter.
  • It seems that teamDriveId is deprecated. Please use driveId. Ref

When above points are reflected to your script, it becomes as follows.

Modified script:

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']

Reference:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.