16

Is there any URL google has that contains the raw data for the file? using https://drive.google.com/file/d/FILE_ID just takes you to a 'share' section of the file... say I have a .js file on GDrive. If you go to their share link, they have a share page. Is there any link to get the raw javascript from the file, as to use in a <script src="google_link_or_whatever">?

parzivail
  • 171
  • 1
  • 1
  • 8
  • Does this help? http://googleappsdeveloper.blogspot.nl/2012/11/announcing-google-drive-site-publishing.html – Dave Morrissey Jul 18 '14 at 23:06
  • @DaveMorrissey It probably would, thanks, but i'm trying to stay away from APIs. :D – parzivail Jul 18 '14 at 23:13
  • possible duplicate of [Google Apps Script How to link to JS or CSS file on Google Drive](http://stackoverflow.com/questions/15110264/google-apps-script-how-to-link-to-js-or-css-file-on-google-drive) – Fraser Jul 21 '15 at 10:31

2 Answers2

9

First, go to the sharing settings for your document and choose "Anyone with a link." It will generate a link in the format https://drive.google.com/file/d/XXX/view?usp=sharing.

Now you can use the following URL format: https://drive.google.com/uc?id=XXX

Note that I'm seeing an HTTP redirect when I do this, so use curl -L on the command line or otherwise make sure that your HTTP client follows redirect.

a paid nerd
  • 28,574
  • 30
  • 121
  • 167
5

NOTE - THIS WAS THE SOLUTION BUT IT NO LONGER WORKS - SEE COMMENT BY @Bobby Fritze below

No API's and no JS necessary. Confirmed now working on latest version of Drive. Great workaround for if your server doesn't use https but a vendor plugin demands https to call in a CSS or other file:

  1. On the folder with your intended file (e.g. FILE.css), hit Sharing Settings, then Advanced, then select "Public on the web - Anyone on the Internet can find and view."
  2. In the URL bar (or share link), copy everything after the drive.google.com/drive/u/0/folders/
  3. Use that ID to replace the XX-XXXXXXXXXXXXX in: http://googledrive.com/host/XX-XXXXXXXXXXXXX/FILE.css
  4. Navigate to the appended URL in Step 3 and you will now see your raw data.

My use case below:

<script type="text/javascript">
var vsDisableResize = false;
var vsCssUrl =         'https://cbe7c864b9c1ae8d5be60c7fed3e467334a04d2f.googledrive.com/host/0B9ngkmVbo5T7TDhTTU81M25iNnc/cart.css';
var vsWineryId = '850';
var vsWineListId = '71';

Credit to @chris.huh at: https://productforums.google.com/forum/#!topic/drive/MyD7dgLJaEo

TheSteve0
  • 3,493
  • 1
  • 17
  • 24
Bobby Fritze
  • 192
  • 1
  • 8
  • 1
    What's this code cbe7c864b9c1ae8d5be60c7fed3e467334a04d2f in your URL? – Mudit Jain Jul 15 '16 at 06:19
  • Each folder you create in Drive will a string after the /folders/ in the Url; (that's the string noted in Step 3). The string you're seeing there is output (in a server-side way idk about), because: http://googledrive.com/host/0BxfRpcEmqYiJRjlJUXozTm80ZlE/why.txt will point you to a static Url of the raw data – Bobby Fritze Jul 21 '16 at 13:00
  • 7
    EDIT: Sometime around late 2016/early 2017, this method of retrieving files from Google Drive stopped working. – Bobby Fritze Mar 07 '17 at 07:25
  • 4
    The answer provided here worked for me: https://stackoverflow.com/a/26191472/1215260, i.e. set sharing to public as described above and use this URL: https://drive.google.com/uc?id=YOUR_DOCUMENT_ID – jsaven Feb 16 '19 at 08:39