Google Drive api Android下载Google文档文件

问题描述:

我试图从Google驱动器下载文件。我在Android上使用JAVA API,因为Google说它提供了对Google Drive的更多控制权。

I am trying to download files from Google drive. I am using the JAVA API for on android since Google says it provides more control over Google Drive.

到目前为止,我可以下载文件,但无法下载Google文档文件。

So far I can download files, but I cannot download Google doc files.

我假设这是因为,为了下载Google文档,需要先将其转换为PDF / Word / HTML,然后才能下载它,大小是未知/ 0。

I assume this is because in order to download a Google doc file it needs to be converted to PDF/Word/HTML before I can download it and the same reason why the size is unknown/0.

所以我的问题是如何将Google文档转换为word文档并下载它?

So my question is how can convert a Google doc to a word document and download it?

我假设您正在查找要导出的Doc类型的查询URL

I assume you are looking for URL to query for exporting Doc type

url:'https://www.googleapis.com/drive/v3/files/' + fileId + '/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document'
method: GET
Content-Type: 'application/json'
Authorization: 'Bearer <Your oauth token>'

改变mimeType参数根据允许的m所需的值ime类型此处
响应正文包含导出的文档。
您可以使用以下wget命令测试参数。它将在result.doc中导出文档

Alter mimeType parameter your required value as per allowed mime types here. Response body contains the exported document. You can test parameters with following wget command. It will export document in result.doc

wget  --header="Authorization: Bearer <your Oauth token>"  --header="Content-Type: application/json" --method=GET  'https://www.googleapis.com/drive/v3/files/{FileID}/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document' -O result.doc