Google Apps Script How to link to JS or CSS file on Google Drive
Asked Answered
A

5

10

Can I keep style.css or anyscript.js hosted on a folder on Google Drive and then include the script with a link to the file in Drive? If so.. how?

And here I mean GAS for use on Google Sites... so the script is not located in Google Drive

Autopsy answered 27/2, 2013 at 10:54 Comment(3)
Isn't this functionality supported by Libraries? Or do you have another idea in mind?Cauterant
As far as I know, currently, GAS and libraries can only have .gs or .html files. I want them as .js/.css files. I know they say you can embed it in the HTML file, but that clutters upp the files.Autopsy
Hi Lisa-Marie, could you accept the answer of Ursus which is the correct way to do this now. Thanks!Entity
N
15

UPDATE: As of August 31, 2015 this technique has been deprecated by Google.

Google recent made it possible host a file publicly on Google Drive:

  1. Create a folder in Google Drive
  2. Put any files you want to access publicly in the folder
  3. Share it publicly (needs to be "Public on the web") and copy the folder ID from the "Link to Share". For example, the folder ID from this link: https://docs.google.com/folder/d/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/edit ... is: 0B5AR8ct5SZfSTDZTQjNNVXR4RWM
  4. The URL for each file will be https://googledrive.com/host/ followed by the folder id followed by the filename. For example: if you saved style.css in the folder in step #1: https://googledrive.com/host/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/style.css
Nestornestorian answered 27/2, 2013 at 12:53 Comment(2)
Now URLs look different... doesn't seem to work anymore. Even examples on Google Developers blog are not working anymore: googleappsdeveloper.blogspot.ca/2012/11/…Blackheart
With some changes in Drive Google was having some issues: productforums.google.com/forum/#!topic/drive/MyD7dgLJaEoNestornestorian
B
29

Google seem to have changed it.

At the time of writing, a link to the raw data works with the following link format:

https://drive.google.com/uc?id=YOUR_DOCUMENT_ID

Blackheart answered 4/10, 2014 at 9:31 Comment(3)
Big upvote for posting the changes. Where did you gain this information from? Is it documented at Google or other? Please provide a link if you have it. ThxTruancy
@daylight no idea to be honest. Was quite desperate to find an answer and while googling and trying out all possible solutions, I've found and tested this one.Blackheart
Is it just my method of opening the URL, or does this method not work for files over 200mb because google shows a "Can't scan for viruses" warning when I try to use this method.Airline
N
15

UPDATE: As of August 31, 2015 this technique has been deprecated by Google.

Google recent made it possible host a file publicly on Google Drive:

  1. Create a folder in Google Drive
  2. Put any files you want to access publicly in the folder
  3. Share it publicly (needs to be "Public on the web") and copy the folder ID from the "Link to Share". For example, the folder ID from this link: https://docs.google.com/folder/d/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/edit ... is: 0B5AR8ct5SZfSTDZTQjNNVXR4RWM
  4. The URL for each file will be https://googledrive.com/host/ followed by the folder id followed by the filename. For example: if you saved style.css in the folder in step #1: https://googledrive.com/host/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/style.css
Nestornestorian answered 27/2, 2013 at 12:53 Comment(2)
Now URLs look different... doesn't seem to work anymore. Even examples on Google Developers blog are not working anymore: googleappsdeveloper.blogspot.ca/2012/11/…Blackheart
With some changes in Drive Google was having some issues: productforums.google.com/forum/#!topic/drive/MyD7dgLJaEoNestornestorian
C
1

What about Google's own recommendation in the HTML Service Best practices, for Separating HTML, CSS and Javascript?

Classicize answered 12/2, 2014 at 14:38 Comment(0)
N
1

It still works, the URLs just look a bit different. Answered already over here, but the steps are:

  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.

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

Novokuznetsk answered 4/3, 2016 at 0:54 Comment(0)
H
0

I found out that the direct link workaround has changed a bit. You can download any file using the following url now:

https://drive.google.com/uc?export=download&id=[PutYourIdHere]

This is how you extract the id of your file:

https://drive.google.com/file/d/1gIax1-2397HJFLSJFOIUWEIJ23/view?usp=sharing

Here 1gIax1-2397HJFLSJFOIUWEIJ23 is the ID

Huey answered 25/5, 2020 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.