7

I'm building an application to automatically trigger a download of a file share with a user. For example, this was straight forward to implement for Dropbox links, as is outlined here.

I'm trying to implement the same functionality for Google Drive links, but running into difficulties. Right now the app takes the third part of the link (the file ID) and appends it to "https://docs.google.com/uc?export=download&id= ". But this seems unreliable, especially as there are at least 3 different link formats for shared files that I've found (https://drive.google.com/file/d/xyz, https://docs.google.com/document/d/xyz etc.). Does anyone know of a generally applicable and reliable way to grab the files from Google Drive shared links, like the process outlined for Dropbox above?

Finally, we have Oauth access to a users Drive account. For files shared with them that have sharing settings set to 'Private' (or anything other than 'Public on the web' or 'Anyone with the link'), I've been researching (with little success) if it is possible to download those files on behalf of the Oauth authenticated user - does anyone have any insight on this?

Any insight/suggestions would be greatly appreciated.

[Update] The "private" shared files can be downloaded from the users Drive account - they're automatically added to the 'Shared with me folder', so just need a reliable way to grab the file ID.

Cian
  • 1,579
  • 3
  • 14
  • 28
  • You shouldn't construct your own URLs. You need to retrieve the File resource (either directly by ID, or via a query) and then use whichever of the various download/export URLs best fits your use case. – pinoyyid Nov 27 '13 at 06:34
  • Any suggestions on grabbing the ID in from the link in the first place? Looking for a reliable way to do this. – Cian Nov 27 '13 at 16:02
  • https://developers.google.com/drive/v2/reference/files/list – pinoyyid Nov 28 '13 at 04:07
  • @pinoyyid - how can files list be used to determine the ID of a file from the shared URL? – Cian Nov 29 '13 at 13:02

1 Answers1

1

From my understanding of drive, you need to look in separate places for different file types:

  • /document/: Documents
  • /presentation/: Presentations
  • /spreadsheet/: Spreadsheets
  • /forms/: Forms
  • /drawings/: Drawings

Other than that, there doesn't seem to be a way to retrieve the documents.

Msmith
  • 23
  • 7
  • Then feel free to give your own answer. – Msmith Nov 26 '13 at 19:41
  • 1
    Getting the file ID reliably from the linked file is the real problem, because of the variation in the link formats. – Cian Nov 26 '13 at 20:50
  • That would be the problem with using this... but you should be able to parse out the file type and use that to get the sub-folder needed. Again, it doesn't seem that they host all of the files under the same sub-folder, unfortunately. – Msmith Nov 26 '13 at 21:02
  • A user could have any type of file in any folder on their Drive? Getting the file type from the URL could be useful tho, for conversion from docs format. – Cian Nov 26 '13 at 21:07
  • Mainly i use documents, because I use my drive to write papers and such. Google Drive's folders have no effect on a typical file's url. So if you have a file in the X folder and a file in the Y folder, even though they are visually in different folders, their URL folders stay the exact same. So a file in X folder will be: https://docs.google.com/a/(site).org/document/d/fileinXfolder/ and a file in Y folder will be: https://docs.google.com/a/(site).org/document/d/fileinXfolder/ – Msmith Nov 26 '13 at 21:21
  • The problem described is with downloading the files received through Drive share links - specifically getting the file ID somehow. The location of the file in the senders Drive doesn't matter. – Cian Nov 27 '13 at 12:38