4

I want to create a folder on google drive using the Python API. Here is the function:

def create_folder(file_path, parentId=None):
    body = {
    'name': os.path.basename(file_path),
    'mimeType': "application/vnd.google-apps.folder"
    }
    if parentId:
        body['parents'] = parentId

    results = service.files().insert(body=body).execute()
    return results

But it gives the error:

AttributeError: 'Resource' object has no attribute 'insert'

I thought it would work just like the get and list methods here- https://developers.google.com/drive/v2/reference/files#methods

I found an answer here: How can I create a new folder with Google Drive API in Python?

What am I missing?

0

2 Answers 2

8

You're encountering 'Resource object has no attribute insert' because you are using Google Drive API v3. The method 'files.insert' is suitable only for Drive API v2. You may use 'files.create' instead of 'files.insert'.

For more information, please follow this link: https://developers.google.com/drive/v3/web/migration

2
0

There seem to be two problems:

  • When I execute your code a folder is created and there is no error message. Maybe you can post the code where you initialize the "service" variable. If the drive stuff is not probably initialized, that may fail.
  • In order to create a folder with a specific name use "title" instead of "name". Using name also works but the folder will show as "New Folder"

Not the answer you're looking for? Browse other questions tagged or ask your own question.