google-drive-api - 将 Google Drive 文档导出为支持的 MIME 类型

标签 google-drive-api

我正在使用 rest api(版本 3)将文件上传到 Drive,我可以上传这些文件。但是当我尝试导出该文件时,我得到了

403:Export only supports Google Docs.

如果我在驱动器编辑器上创建文件然后导出它,它会被正确导出。
在 API 的第 2 版中,我可以看到有一个选项
convert=true

但是在版本 3 中没有这样的选项。

Stack over Flow link
但这适用于第 2 版

最佳答案

uploading files ,您只需要指定 Google docs mimeType 使它们成为 Drive 文件。

该文档给出了将 .csv 文件转换为 Sheets 文件的示例。

File fileMetadata = new File();
fileMetadata.setName("My Report");
fileMetadata.setMimeType("application/vnd.google-apps.spreadsheet");

java.io.File filePath = new java.io.File("files/report.csv");
FileContent mediaContent = new FileContent("text/csv", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());

关于google-drive-api - 将 Google Drive 文档导出为支持的 MIME 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548456/

相关文章:

android - 无法使用编程预选帐户启动 android google drive 应用程序

c# - 在 C#.Net 中将 ParentReference 从 Google Drive Apis v2 迁移到 v3

google-drive-api - 无法从Google Drive API检索文件内容

tensorflow - 如何使用已安装的 Google 驱动器中的 Tensorflow 在 Google Colab 笔记本中加载图像

python - Google Drive api - 不支持 map 导出(python)

android - 用于与 Google Drive 集成的应用程序的最小 Android API

google-drive-api - Google Drive 上的追加模式

javascript - 使用javascript读取文件并将其发送到服务器

google-drive-api - 接收访问 token 谷歌驱动器API,C#

python - 驱动器 API 错误 Python : FileNotFoundError 'credentials.json'