Accessing Google Drive as JSON via jQuery
I am trying to use google drive as a testbed for hosting JSON files. This allows me to transfer my client files to my fellow designer without the hassle of setting up a WebApi controller or nodeServer node.
I am trying to call it like this in my JavaScript:
$.ajax({
type: "POST",
dataType: 'json',
contentType: "application/json",
url: "https://drive.google.com/file/d/0B-6bXDnuW6gPT3NUQ1VSQW12Z1k/view?usp=sharing"
})
.done(function( data ) {
// reference data here
alert( data );
});
And this is the data I'm trying to get back:
[{
"Name": "Soren Kierkegaard",
"Timestamp": "1301190400",
"Comment": "Life is understood backwards, but it is lived forwards.",
"StaticURL": "./img/some_guy2.png"
}]
But I am returning:
XMLHttpRequest cannot load https://drive.google.com/file/d/0B-6bXDnuW6gPT3NUQ1VSQW12Z1k/view?usp=sharing . There is no "Access-Control-Allow-Origin" header in the requested resource. Therefore, the original "null" is not allowed.
This makes me suspect that the browser (or perhaps jQuery?) Wants the response header to contain an Access-Control-Allow-Origin key / value pair.
If I can't add this as a key / value pair to JSON? This would add an outer layer to my data, but I would have to parse it OK on the JavaScript side I think it is.
I've tried several combinations of GET / POST and data types. Jsonp seems to be prompting me to install the script on Google and I don't see an easy way to configure jsonp on Google or ask Google to add something to their response headers.
Related StackExchange Posts Using Different Platforms and Different Results: JSON Not Parsed
source to share
I managed to get around this by using myjson.com as the host provider.
I honestly don't understand how static json files pose a security risk. Dynamic json -maybe- but if it is generated from a file in Google Drive it will not be dynamically generated, right?
The Google Drive API requires a workaround to get past it ... which is not conducive to rapid prototyping or setting up a staging environment.
source to share
On google drive to get file content you need to change url, use googledrive / host link as below: Use link like " https://googledrive.com/host/0B-6bXDnuW6gPT3NUQ1VSQW12Z1k "
source to share