YuviSense: Codin Kid

Yuvi, a 17 year old wannabe geek from India.
  • rss
  • Blog
  • Photography
  • Indians on Twitter
  • About Me
  • Contact

Calling Google AJAX Search API from C#

December 30, 2006 | 2:52 pm

Everyone and their aunt knows that Google’spulled the plug on the SOAP Search API and pulled the SDK from their site. I expected that, but I figured that it’ll be replaced by POX over HTTP. Or JSON. I could’ve accepted even, uhm, CSV. XLSX even. But, I never actually expected it to be an opaque Javascript block, and still be called an API.

But, fear not! Davanum Srinivas has waded through the obfuscated Javascript and produced this piece of Java code that’ll give you a JSON feed of the search terms. It didn’t take me much time to convert it to C#:

using System.Net;
using System.IO;
using System;
public class GoogleAJAXSearchAPI
{
    public static void Main(String[] args)
    {
        String endpointURL =
                    “http://www.google.com/uds/GwebSearch?” +
                    “callback=GwebSearch.RawCompletion” +
                    “&context=0&lstkp=0&rsz=small&hl=en&” +
                    “sig=8656f49c146c5220e273d16b4b6978b2&” +
                    “q=Yuvi&” +
                    “key=xxxxxxxxxxxxxxxxxxxxx&v=1.0″;
        WebRequest wrq = WebRequest.Create(endpointURL);
        WebResponse wrs = wrq.GetResponse();
        StreamReader sr = new StreamReader(wrs.GetResponseStream());
        while (!sr.EndOfStream)
        {
            Console.WriteLine(sr.ReadLine());
        }
 
    }
}

The q parameter is your search term, while the key is yourGoogle AJAX search API Key. Note that Google may change this any time, without notice, causing code that was working to suddenly stop working and people will blame it on C#. Now, all we need is a library for parsing JSON….

Categories
Tech
Comments rss
Comments rss
Trackback
Trackback

« StatBot: Analysis of Scobleizer.com – Part 0 General Statistics StatBot: Analyzing Scobleizer.com – Part 1 Link Analysis »

4 responses

Excellent info. I a beginner to C# programming. Could you

Hui K. | January 17, 2007 | 8:33 am

Excellent info. I a beginner to C# programming. Could you provide a full working example in C#.

Many thanks.

[...] fear not, after a quick search, I tracked down

Monkey see, monkey build - The mumblings of Clint Rutkas » Dealing with Google Ajax Search Calls in C# | October 3, 2007 | 7:05 pm

[…] fear not, after a quick search, I tracked down Yuvi and this genius has a bit of c# code to get the results from the call.  Yuvi transcoded Davnum Srinivas’s Java code which properly dealt with the obfuscated […]

Your Sample was really useful, Thanks! this code returns only the

Bahar | February 5, 2008 | 7:50 am

Your Sample was really useful, Thanks!
this code returns only the first 4 results from Google, how can I get more results (about 10 - 15)?

There's a C# wrapper for Google Search API called GAPI.Net

Liam | August 13, 2008 | 1:18 pm

There’s a C# wrapper for Google Search API called GAPI.Net on CodePlex.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contact Me

Email: yuvipanda@gmail.com
IM: yuvipanda@msn.com
GTalk: yuvipanda

My Photos


View my Flickr Page

My Badge


IndiBlogger - Where Indian Blogs Meet

Archives

  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox