November 19, 2006

Secret Google JSON API

Google already offers feeds for Google News, Blog Search, Google Video, so you can use the search results in your applications or sites. There's also a Google API for web search that uses SOAP, but it's limited to 1000 queries per day.

For the first time, Google offers a new kind of API, unified for web search, image search, blog search and video search. The API uses JSON, so creating applications in JavaScript is easy. You must know that this API is unofficial, so the details can change.

Google JSON API is the foundation of SearchMash, an experimental site created by Google.

So how do you get the search results using this API? You just load this page:
http://www.searchmash.com/results/[query]. You just have to replace [query] with the actual query. If you use this format: http://www.searchmash.com/results/[query]?i=11&n=10, you request 10 search results, starting with the result number 11. The formats for image search, blog search and video search are:

http://www.searchmash.com/results/images:[query]
http://www.searchmash.com/results/blogs:[query]
http://www.searchmash.com/results/video:[query]

The JSON object you get from Google has a list of members that are very easy to understand, like: estimatedCount (the number of search results) or results, which is an array that describes the search results. To make cross-domain requests, you may need to create a web proxy, like shown here.

15 comments:

  1. Thanks for the heads up, mate!

    I'm writing a parser for the thingy, just for kicks ;), and found out that the following was a good regex. Just so you guys know...

    m/\"([^"]*)\":\"([^"]*)\"/g

    ReplyDelete
  2. You don't have to write a parser yourself. There are JSON decoders for every platform/language.

    ReplyDelete
  3. This API was good but have a lot of limitations.
    It's easy write a parser yourself and if you do it you don't have any limitations.

    Here is a free online Google parser:
    Google parser

    If you want to read the article about it:
    Get Google results in a list of clean URLs

    ReplyDelete
  4. Is there any way to make the JSON responce call a function in your javascript like the Yahoo API e.g "callback=processresults"?

    If not, how do you access the JSON object directly??

    Any help would be much appreciated

    ReplyDelete
  5. Guys? Can we have a callback function?

    I'll be your best friend!

    ReplyDelete
  6. PHP5's JSON_decode function just does it. if you are using PHP5 this might be helpful:

    $gJSON=file_get_contents($url);
    $gArray = JSON_decode($gJSON,true);

    this converts the JSON formatted array to PHP array.

    ReplyDelete
  7. can i download the google json api source? I need implement this in my page and i can't depend of that page :P

    ReplyDelete
  8. SearchMash taken offline...

    ReplyDelete
  9. can you modify it so it works like "google to some string, parse out urls and names of links [:10], print them out"?

    ReplyDelete
  10. I think searchmash.com closed this api forever. But we can develop another one :))

    ReplyDelete
  11. I think that Google closed SearchMash completely.
    Oh, well... Other opportunities will come :)

    ReplyDelete
  12. yea no more search mash it seems - bing and yahoo still have open api's

    ReplyDelete

Note: Only a member of this blog may post a comment.