【问题标题】:How to set mimeType when use files export of google-drive-api?使用 google-drive-api 的文件导出时如何设置 mimeType?
【发布时间】:2019-01-21 05:32:56
【问题描述】:

我使用[google-drive-sdk],我了解如何导出文件here

我知道fileIdmimeType这两项是必需的。

当我将mimeType 设置为application/vnd.google-apps.spreadsheet 时,我点击 按钮EXECUTE,响应为:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "The requested conversion is not supported.",
    "locationType": "parameter",
    "location": "convertTo"
   }
  ],
  "code": 400,
  "message": "The requested conversion is not supported."
 }
}

好像是我设置的mimeType不对,请问mimeType怎么设置?

【问题讨论】:

  • 很遗憾,Google Docs 文件无法导出为 Google Docs 的 mimeType。在你的情况下,那是application/vnd.google-apps.spreadsheet。错误的原因是由于这个 mimeType。你可以看到About: get可以导出的mimeTyps。当您将exportFormats 放入fields 时,您可以看到mimeTypes。例如,当您将application/json 设置为mimeType 在 Files: export 时,您可以在结果屏幕上看到 PDF 数据。如果这对您的情况没有帮助,我深表歉意。
  • 在这个方法中,mimeType应该填什么才能让操作通过?
  • 我为我糟糕的英语水平道歉。如果this method你说是“文件:导出”,例如,用application/json而不是application/vnd.google-apps.spreadsheet怎么样?
  • 对不起。那是application/pdf。这是我的错。
  • 还可以看到可以导出的mimeTypes。 developers.google.com/drive/api/v3/reference/about/…点击按钮即可执行。

标签: python google-api google-drive-api google-api-python-client


【解决方案1】:

正如田池所说,当我使用Files: export时,我将text/csv设置为mimeType,则响应没有错误。

现在您可以看到正确的响应:

其实使用Files: get可以得到详细的下载信息。 例如,在节点exportLinks

“导出链接”:{ "application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=ods", "文本/制表符分隔值": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=tsv", "申请/pdf": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=xlsx", "文本/csv": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=csv", "应用程序/zip": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=zip", "application/vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=YpDWTfWh5VFtchFYA&exportFormat=ods" }

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 2016-10-06
    • 2017-04-06
    • 2017-10-10
    相关资源
    最近更新 更多