JSON Examples?
pmonday
Registered Users Posts: 11 Big grins
I'm relatively naive ( :scratch ) on JSON could use a couple questions answered. I am trying to build a SmugMap-like interface from blogs.sun.com/blackbox. The RSS feed has the exact information I need, but you can't load it from a web page because of the security implications (this thread documents it a bit, http://www.dgrin.com/showthread.php?t=26610&highlight=access)
So, the JSON questions I have
Paul Monday
So, the JSON questions I have
- Should the JSON API be able to get around this (I am guessing it will not since you are doing essentially the same thing from a security perspective...)
- I need a jump start and can find 0 documentation on using the JSON API in the 1.2.0 API documents (examples are the most critical), am I missing something on the web site? Especially a jump start for folks like me trying to consume smugmug information from a non-smugmug site :-) Or, now that I'm looking at the APIs, is the idea that we should be viewing the page source and working with the API examples under the specific method we want to be using?
Paul Monday
0
Comments
In talking with a few folks here and looking around the net a bit, it looks like pure use of JSON still requires that I load the document from a different domain, thus forcing the sandbox security violation...bummer for me.
The solution, theoretically (with respect to JSON), is JSONP...but this appears to be enabled by the server side (y'all at SmugMug)...
Alternatives appear to be
- I could author a proxy javascript somewhere and put it on our server (not possible since I'm pure client side but is very similar to what I'm doing today anyway)
- I could use some IFrame hack that I don't understand yet (and I'm not sure if I could implement in the blogging infrastructure)
Still trying to figure this out though...there's got to be a more direct way to replace my current polling application on my pc that reformats info into javascript variables, uploading it to a middle-man web site and importing the .js from my client.
I suspect the google maps api, while not json, is a bit more like one would expect a pure client API to be like (import a javascript library and use it directly). That's an interesting solution since, technically, it seems like you have the same so called security violation as the remote document loading
Paul
http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html
Kevin
I believe that this is dependent on server side support. The example they use is from another JSON service. One of the parameters is a callback=javascriptobject where the javascript object can be a function. The server then wraps the JSON result in a function call so that it is called on the return of the information.
Here is the example of the callback function supported in a json service:
http://developer.yahoo.com/common/json.html#callbackparam
Here is another example in the Google service:
http://googlemapsapi.blogspot.com/2007/03/creating-dynamic-client-side-maps.html
Is there support for a callback on the SmugMug JSON API, I didn't see it anywhere?
Paul
var oJSON = eval('(' + response + ')');
also, you might want to read this article about how to proxy xmlhttp requests to get around cross domain security.
SmugMug API Developer
My Photos
you might want to read this article about yahoo's json api.
I do NOT have access to the web server to host the proxy (i'm on blogs.sun.com and do not own the infrastructure). I am purely in the client space. Use of the callback mechanism in the Yahoo API (and Google) allows me to build a pure client rather than having to load a special proxy script on my web server. As aarone notes, by having YOUR JSON request format the callback, it calls my function, which is permitted by the sandboxes (I still don't see why since it seems like a huge security no-no...but hey, I'm going to go with it).
Thanks....that's cool.
I'm adding a JSONCallback parameter, I will let you know when it's released.
SmugMug API Developer
My Photos
Thanks David...I hate to be an anxious dork, but our new tour starts at the end of this week and I have to finish the code while I'm in the booth at JavaOne, do these type of enhancements usually take a while?
Thanks,
Paul
The JSONCallback parameter is now live.
SmugMug API Developer
My Photos