在Google云端硬盘中创建Google文档 [英] Create google doc in google drive

查看:153
本文介绍了在Google云端硬盘中创建Google文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am able to create text and .doc files in the Google drive using the Google drive API. but when i set the mime type as application/vnd.google-apps.document the app crashes with log

可能无法使用此方法创建快捷方式文件.使用 改为DriveFolder.createShortcutFile()

May not create shortcut files using this method. Use DriveFolder.createShortcutFile() instead

这是尝试创建文件的方式

This is how try to create the file

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创建google文档?

Is it possible to create google documents from the Drive API ?

推荐答案

我不确定您为什么要使用Metadatachangeset类尝试此操作. 顾名思义,此类更好地用于获取文件的元数据.

I'm not sure why you are trying this with the Metadatachangeset class. This class is, like the name says, better used for getting metadata of files.

要创建/插入新文件,应使用File类.

To create/insert a new file you should use the class File.

下面是一个示例: https://developers.google.com/drive/v2/reference/files/insert#examples

此链接可能对您很有帮助. https://developers.google.com/drive/v2/reference/files/insert

Very helpful might be this link. https://developers.google.com/drive/v2/reference/files/insert

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

Your mime_type ".document" should be correct. https://developers.google.com/drive/v2/web/mime-types

这篇关于在Google云端硬盘中创建Google文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆