goe*_*ash 4 python google-drive-api
我想使用Python API在Google驱动器上创建一个文件夹。这是函数:
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
Run Code Online (Sandbox Code Playgroud)
但是它给出了错误:
AttributeError: 'Resource' object has no attribute 'insert'
Run Code Online (Sandbox Code Playgroud)
我认为它会像此处的get和list方法一样工作-https
://developers.google.com/drive/v2/reference/files#methods
我在这里找到了答案: 如何使用Python中的Google Drive API创建新文件夹?
我想念什么?
您遇到的是“ 资源对象没有属性插入 ”,因为您使用的是Google Drive API v3。方法“ files.insert”仅适用于Drive API v2。您可以使用“ files.create ”而不是“ files.insert ”。
有关更多信息,请点击以下链接:https : //developers.google.com/drive/v3/web/migration