3

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.

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

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.

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

Maclaren
  • 259
  • 3
  • 13

3 Answers3

2

See Google REST API

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

The Drive API allows you to download files that are stored in Google Drive. Also, you can download Google Documents (Documents, Spreadsheets, Presentations, etc.) and export them to formats that your app can handle. Drive also supports providing users direct access to a file via a link.

jaxarroyo
  • 190
  • 2
  • 15
2

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

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
s007
  • 728
  • 6
  • 12
  • If you can include how to retrieve the access token in your solution (I have searched in many places for how to do this and have not found any solutions that have worked), then I will give you the 150-point bounty. Just for clarification, in my app, the user already has to authorize the app to access their drive before the app opens the file because the app opens Google Drive's file picker. – Daniel Jul 17 '16 at 22:06
  • 1
    I use chrome.identity.getAuthToken api to retrieve oauth token using javascript. Is your app chrome app or mobile app ? Are you using any google api library and which language (javascript, python, java) ? – s007 Jul 18 '16 at 15:42
  • 1
    You should use GoogleAuthUtil class and getToken given in Android Api's given [here](https://developers.google.com/android/reference/com/google/android/gms/auth/GoogleAuthUtil) to retrieve OAuth token. – s007 Jul 20 '16 at 15:47
  • I hope my answers helped. – s007 Jul 23 '16 at 05:02
0

Mimetypes are used to specify which format you want to download the file in.

So the problem was there was a space in my MimeType... that was giving me the error.

But use the following link for converting to different formats. Scroll to where it says Downloading Google Documents

Link

Maclaren
  • 259
  • 3
  • 13