【问题标题】:Create google doc in google drive在谷歌驱动器中创建谷歌文档
【发布时间】:2016-03-11 18:38:24
【问题描述】:

我能够使用 Google Drive API 在 Google Drive 中创建文本和 .doc 文件。但是当我将 mime 类型设置为 application/vnd.google-apps.document 时,应用程序崩溃并显示日志

可能无法使用此方法创建快捷方式文件。利用 DriveFolder.createShortcutFile() 代替

这是尝试创建文件的方法

MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("New file")
.setMimeType("application/msword")// this works
//.setMimeType("application/vnd.google-apps.document") //this does not work
.setStarred(true).build();


Drive.DriveApi.getRootFolder(getGoogleApiClient())
.createFile(getGoogleApiClient(), changeSet, null /* DriveContents */)
.setResultCallback(fileCallback);

是否可以从 Drive API 创建谷歌文档?

【问题讨论】:

  • 查看 Web 服务的 Create Files,Mime 类型类似于创建快捷方式(这是日志所指示的)。我认为您当前创建文件的方式没有任何问题。如果您想了解更多相关信息,可以查看 Drive API for Android 文档中的 Creating Files
  • Google 文档不是真正的文档,它们是虚拟的,不存储在驱动器文件夹区域中。
  • @Brianfromstatefarm 所以不可能使用 API 创建新的 google doc 文件?
  • 在使用 c# 和 REST API 时,我发现尝试提取文件时需要单独调用来请求 google docs 文件。基本上必须告诉谷歌文档将文件转换为输出格式。我正在寻找文档的链接。

标签: android google-drive-api


【解决方案1】:

你不应该使用application/vnd.google-apps.file 来创建吗?

【讨论】:

    【解决方案2】:

    我不确定您为什么要使用 Metadatachangeset 类进行此操作。 这个类,顾名思义,更适合用于获取文件的元数据。

    要创建/插入新文件,您应该使用 File 类。

    这里是一个例子:https://developers.google.com/drive/v2/reference/files/insert#examples

    这个链接可能很有帮助。 https://developers.google.com/drive/v2/reference/files/insert

    您的 mime_type ".document" 应该是正确的。 https://developers.google.com/drive/v2/web/mime-types

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多