Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a folder using Google Drive API : Resource has no method "insert'

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?

like image 646
goelakash Avatar asked Feb 07 '23 21:02

goelakash


1 Answers

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

like image 163
Android Enthusiast Avatar answered Feb 13 '23 03:02

Android Enthusiast