【发布时间】:2017-07-31 04:58:28
【问题描述】:
我正在使用 PyDrive 在 Google Drive 中创建文件,但我在处理实际的 Google Doc 类型项目时遇到了问题。
我的代码是:
file = drive.CreateFile({'title': pagename,
"parents": [{"id": folder_id}],
"mimeType": "application/vnd.google-apps.document"})
file.SetContentString("Hello World")
file.Upload()
如果我将 mimetype 更改为 text/plain,这可以正常工作,但它给了我错误:
引发 ApiRequestError(error) pydrive.files.ApiRequestError: https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“提供的 MIME 类型无效”>
如果我保留 MimeType 原样,它也可以正常工作,但删除对 SetContentString 的调用,所以看起来这两件事不能很好地结合在一起。
创建 Google Doc 和设置内容的正确方法是什么?
【问题讨论】:
-
附加:基于此documentation,如果未提供任何值,Drive 将尝试从上传的内容中自动检测适当的值。除非上载新修订,否则无法更改该值。这是一个相关线程:stackoverflow.com/questions/43988753/…
标签: python google-drive-api pydrive