简体   繁体   English

Google Drive api Android下载Google doc文件

[英]Google Drive api Android download Google doc file

I am trying to download files from Google drive. 我正在尝试从Google云端硬盘下载文件。 I am using the JAVA API for on android since Google says it provides more control over Google Drive. 我在Android上使用JAVA API,因为Google表示它可以更好地控制Google云端硬盘。

So far I can download files, but I cannot download Google doc files. 到目前为止我可以下载文件,但我无法下载Google doc文件。

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 doc文件,我需要将其转换为PDF / Word / HTML才能下载它,原因与大小未知/ 0相同。

So my question is how can convert a Google doc to a word document and download it? 所以我的问题是如何将Google文档转换为word文档并下载?

See Google REST API 请参阅Google REST API

https://developers.google.com/drive/web/manage-downloads https://developers.google.com/drive/web/manage-downloads

The Drive API allows you to download files that are stored in Google Drive. Drive API允许您下载存储在Google云端硬盘中的文件。 Also, you can download Google Documents (Documents, Spreadsheets, Presentations, etc.) and export them to formats that your app can handle. 此外,您还可以下载Google文档(文档,电子表格,演示文稿等)并将其导出为您的应用可以处理的格式。 Drive also supports providing users direct access to a file via a link. Drive还支持用户通过链接直接访问文件。

I assume you are looking for URL to query for exporting Doc type 我假设您正在寻找用于查询导出Doc类型的URL

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>'

Alter mimeType parameter your required value as per allowed mime types here . 根据允许的mime类型在此处更改mimeType参数所需的值。 Response body contains the exported document. 响应正文包含导出的文档。 You can test parameters with following wget command. 您可以使用以下wget命令测试参数。 It will export document in result.doc 它将导出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

Mimetypes are used to specify which format you want to download the file in. Mimetypes用于指定要下载文件的格式。

So the problem was there was a space in my MimeType... that was giving me the error. 所以问题是我的MimeType中有一个空格......这给了我错误。

But use the following link for converting to different formats. 但请使用以下链接转换为不同的格式。 Scroll to where it says Downloading Google Documents 滚动到Downloading Google Documents

Link 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM