2016-03-02 149 views
2

我能够使用Google驱动器API在谷歌驱动器中创建文本和.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); 

是否有可能从驱动器API创建谷歌文件?

+0

查看Web服务的[创建文件](https://developers.google.com/drive/v3/web/integrate-create#create_a_shortcut_to_a_file),Mime Type类似于创建快捷方式(即日志显示的内容)。我目前没有看到你如何创建文件。如果您想了解更多信息,可以查看Drive API for Android文档中的[创建文件](https://developers.google.com/drive/android/create-file) – adjuremods

+0

Google文档不是真实的文件,它们是虚拟的,并不存储在驱动器文件夹区域中。 –

+0

@Brianfromstatefarm所以它不可能使用API​​创建一个新的谷歌文档文件? –

回答

0

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

+0

。文档应该是正确的:https://developers.google.com/drive/v2/web/mime-types – zypro

0

我不知道你为什么要用Metadatachangeset类来试试这个。 这个类就像名字所说的那样更适合获取文件的元数据。

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

下面的例子: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