Google Drive raw data? - javascript

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">?

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.

Sharing link:
https://drive.google.com/file/d/YOUR_ID/view?usp=sharing
Raw download link:
https://drive.google.com/uc?export=download&id=YOUR_ID

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:
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."
In the URL bar (or share link), copy everything after the drive.google.com/drive/u/0/folders/
Use that ID to replace the XX-XXXXXXXXXXXXX in: http://googledrive.com/host/XX-XXXXXXXXXXXXX/FILE.css
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

Related

Cordova - Saving/ Downloading a backup JSON file that is dynamically generated

I am building an HTML5 phonegap application. This app exports data so that the user can backup and restore any time. I'm doing this exporting with the following javascript code:
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(this.data, null, "\t"));
var dlAnchorElem = document.createElement('a');
dlAnchorElem.setAttribute("href", dataStr);
dlAnchorElem.setAttribute("download", "data.json");
document.body.appendChild(dlAnchorElem);
dlAnchorElem.click();
This generates an anchor tag with an encoded file and clicks so it downloads. Works great on browser, but does nothing in a compiled Cordova application.
After doing some research, I found that the default solution would be to use a download plugin for Cordova, specifically this one: https://github.com/apache/cordova-plugin-file-transfer
I read the documentation, but it does not seem to take an encoded file as parameter, but an encoded URL for download. Also, it takes the save path on the phone, which I prefer would just default to the download folder.
My question is: What is the best way to achieve this, considering I'm dynamically generating the JSON backup file. Is there perhaps an AndroidManifest directive that allows for file downloads?
After some research and trying many different hacks, I came to the conclusion that it's currently not allowed natively with cordova or with the available plugins. My solution was to, instead of writing to the filesystem, use the web share api to let the user export the way he finds best (including file, if he chooses dropbox, onedrive or google drive).

How to make github pages url case insensitive?

Website works for
jerrygoyal.github.io/Flash-Clipboard
but not for (404 error):
jerrygoyal.github.io/flash-clipboard
jerrygoyal.github.io/FLASH-clipboard
jerrygoyal.github.io/flaSH-CLIPboard
and so on
You get the idea!
How can I make the url case-insensitive?
I've never worked on Jekyll and not sure if my project pages are using jekyll or not. I only created an index.html page and put inside the docs folder of the repository.
I'm using a custom domain (www.jerryfactory.com) to map jerrygoyal.github.io
Here's the URL to my Github Organisation site : https://github.com/JerryGoyal/jerrygoyal.github.io
And URL for my Github project site:
https://github.com/JerryGoyal/Flash-Clipboard/tree/master/docs
I'm thinking of moving my project site content to my Github Organisation site if it's possible. So if the URL case insensitivity works for only Organisation site it's fine.
Ref: Org and Project Site in Github
How can I make the url case-insensitive?
The short answer is: You cannot / It's not possible in GitHub Pages as of this writing.
The long answer is: Having URLs case-sensitive is a web standard and most webservers will respect that. This has nothing to do with Jekyll or any other similar tool. It's a responsibility of the webserver that is serving the HTML pages that were generated by Jekyll, and in the case of GitHub Pages, they use a *nix-based webserver that is compliant with case-sensitive URLs when locating resources.
A common way to solve this problem is to make sure your pages in Jekyll are always lower-case, which in turn will generate lower-cased URLs.
This shouldn't really be a problem, unless your users are typing the URLs by themselves... And in that case, if you want to be proactive, you can use the jekyll-redirect-from plugin and create redirect entries of the most common ways you believe users will try to access each page.
For example, having the main URL as
augustoproiete.github.io/flash-clipboard
and redirect the ones below to the main one above via jekyll-redirect-from
augustoproiete.github.io/Flash-Clipboard
augustoproiete.github.io/FLASH-CLIPBOARD
There is no direct way to make github page URLs case-sensitive. But, you can use following hack:-
Redirect from 404 page with mixed-case or upper-case URL to lower case URL. Steps to achieve this:-
Just go to your root repo (your_username.github.io).
If not already exist then create a 404.html file and add the following script in it.
<script>
window.onload = () => {
currentURL = window.location.href;
lowerCaseURL = currentURL.toLowerCase();
if (currentURL != lowerCaseURL) {
location.replace(lowerCaseURL);
}
};
</script>
Note:- Make sure your pages/repo name are always in lower-case.
Logic explained with example:-
If your URL is:-
anmol53.github.io/bmi-tracker
and someone tried following URL:-
anmol53.github.io/BMI-Tracker
By default he/she will get 404. Now we will redirect him/her to anmol53.github.io/bmi-tracker by changing case of current URL by using above script.
You can’t make it case-sensitive. Sorry. Case-sensitive URLs are a web-standard. It would be cool if URLs were case-insensitive, but that isn’t true.

Get parameters at the end of URL on Apache Web Server

I have a URL with the following syntax:
https://www.domain.com/pay/a1b2c
In the /pay directory I have a simple payment form. I am using JavaScript to get the URL appendix a1b2c and process it in order to get further data to display in the payment form:
var url = window.location.href;
var appendix = url.split("/").pop();
...
But if I open the URL in the browser, Apache says (of course):
Not Found
The requested URL /pay/a1b2c was not found on this server.
How can I solve this problem? Which Apache config do I need?
I found a solution by asking humbedoo on the Apache Mailing list:
You can use AcceptPathInfo in order to get the appendix.
For example, assume the location /test/ points to a directory that
contains only the single file here.html. Then requests for
/test/here.html/more and /test/nothere.html/more both collect /more as
PATH_INFO.

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

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
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
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:
Create a folder in Google Drive
Put any files you want to access publicly in the folder
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
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
What about Google's own recommendation in the HTML Service Best practices, for Separating HTML, CSS and Javascript?
It still works, the URLs just look a bit different.
Answered already over here, but the steps are:
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."
In the URL bar (or share link), copy everything after the drive.google.com/drive/u/0/folders/
Use that ID to replace the XX-XXXXXXXXXXXXX in: http://googledrive.com/host/XX-XXXXXXXXXXXXX/FILE.css
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
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

Xml to js code problem

So i'm very new to xml to javascript so i thought I would learn from w3schools, but this site
http://www.w3schools.com/xml/xml_to_html.asp shows an example that I can't mimic locally. I copy/pasted the .js and downloaded the xml but I just get a blank screen!
It's working in there try it yourself but not for me? Do I need it on a server or something?
Yes, that code retrieves the XML data from a web server using AJAX. Since you don't have a server running locally, you can change the URL to point directly to the w3school's version:
xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);
Alternatively, play around on their online version ;)
well i guess you have to add the example xml (cd_catalog.xml) to your file system. and you definitively have to access the html file on a server (apache i.e.)
First, ensure that both HTML file (with the Javascript block in it) and XML file are placed in the same directory.
Next, you probably need to place those files under your local web-server and open the HTML like this:
http://[local server host]/ajax.html
instead of opening the file directly from e.g. Windows Explorer:
C:\[path to the file]\ajax.html
For the latter case you'll get an "Access is denied" error.
-- Pavel
Are you running this under a web server or just creating a couple of text files and loading them in your browser?
The "GET" request this relies upon could possibly be failing.
Use Apache or another similar HTTP server and run the example as if it were hosted on the web.

Categories

Resources