简体   繁体   中英

Google Drive create new folder in shared drive

I'm able to create a new folder within a parent folder on my personal Google Drive, but when I try to do it in a shared drive, I get this error:

<HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?fields=id&alt=json returned "File not found:

It looks like a similar problem from this question , which wasn't resolved.

I'm a manager on the account, and other commands, such as creating new files, work fine.

This is the function I'm successfully using when writing to my personal Drive:

def create_folder_in_folder(folder_name,parent_folder_id):

    file_metadata = {
    'name' : folder_name,
    'parents' : [parent_folder_id],
    'mimeType' : 'application/vnd.google-apps.folder'
    }

    file = service.files().create(body=file_metadata,
                                    fields='id').execute()

    print ('Folder ID: %s' % file.get('id')) 

How about this modification?

From:

file = service.files().create(body=file_metadata, fields='id').execute()

To:

file = service.files().create(body=file_metadata, supportsAllDrives=True, fields='id').execute()
  • supportsAllDrives=True is added.
    • I think that the reason of the error message is due to this.

Note:

  • In this case, it supposes that you have the permission for creating the folder to the shared Drive.

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM