Troubleshooting jQuery.getJSON() and Google’s GData API

I’ve just been playing around with calling the Google Books API via jQuery. Here’s some tips in case you run into trouble with “Access to restricted URI denied” or “invalid label” errors:

  • The JSONP parameter is callback=? (jQuery automagically fills in the rest).
  • You need to specify the alt parameter as json-in-script, not just json.

Here is an example of a full AJAX call to the Google Book Search API:

$.getJSON("http://books.google.com/books/feeds/volumes?alt=json-in-script&callback=?",
    { q: "the great gatsby" },
    function(data, textStatus) {
        $.each(data.feed.entry, function(i, entry) {
            // do stuff with each result
        });
    }});

One thought on “Troubleshooting jQuery.getJSON() and Google’s GData API

Comments are closed.