JSON Examples?

pmondaypmonday 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
  • 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?
Thanks,
Paul Monday

Comments

  • pmondaypmonday Registered Users Posts: 11 Big grins
    edited May 1, 2007
    Follow-up, Chattin' with myself
    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 headscratch.gif

    Paul
  • komykomy Registered Users Posts: 19 Big grins
    edited May 1, 2007
    You should be able to use this library to get around the cross domain security issue from your server .

    http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html

    Kevin
  • pmondaypmonday Registered Users Posts: 11 Big grins
    edited May 7, 2007
    komy wrote:
    You should be able to use this library to get around the cross domain security issue from your server .

    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
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited May 7, 2007
    pmonday wrote:
    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
    you don't need the callback.

    var oJSON = eval('(' + response + ')');

    also, you might want to read this article about how to proxy xmlhttp requests to get around cross domain security.
    David Parry
    SmugMug API Developer
    My Photos
  • aaroneaarone Registered Users Posts: 20 Big grins
    edited May 7, 2007
    you don't need the callback.

    var oJSON = eval('(' + response + ')');
    ...which assumes you get 'response' using xmlhttprequest. The point of a callback in the yahoo API is to eliminate the need for xmlhttpreq and proxy by having the remote yahoo script invoke the callback function defined in the local script. The basic trick here is that scripts can be loaded across domains.

    you might want to read this article about yahoo's json api.
  • pmondaypmonday Registered Users Posts: 11 Big grins
    edited May 7, 2007
    aarone wrote:
    ...which assumes you get 'response' using xmlhttprequest. The point of a callback in the yahoo API is to eliminate the need for xmlhttpreq and proxy by having the remote yahoo script invoke the callback function defined in the local script. The basic trick here is that scripts can be loaded across domains.

    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).
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited May 7, 2007
    aarone wrote:
    ...which assumes you get 'response' using xmlhttprequest. The point of a callback in the yahoo API is to eliminate the need for xmlhttpreq and proxy by having the remote yahoo script invoke the callback function defined in the local script. The basic trick here is that scripts can be loaded across domains.

    you might want to read this article about yahoo's json api.

    Thanks....that's cool.

    I'm adding a JSONCallback parameter, I will let you know when it's released.
    David Parry
    SmugMug API Developer
    My Photos
  • pmondaypmonday Registered Users Posts: 11 Big grins
    edited May 7, 2007
    devbobo wrote:
    Thanks....that's cool.

    I'm adding a JSONCallback parameter, I will let you know when it's released.

    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
  • aaroneaarone Registered Users Posts: 20 Big grins
    edited May 8, 2007
    devbobo wrote:
    I'm adding a JSONCallback parameter, I will let you know when it's released.
    awesome! thanks so much!
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited May 11, 2007
    aarone wrote:
    awesome! thanks so much!

    The JSONCallback parameter is now live.
    David Parry
    SmugMug API Developer
    My Photos
Sign In or Register to comment.