2016-03-02 137 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

相關問題