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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With