Calling Google AJAX Search API from C#
December 30, 2006 | 2:52 pmEveryone 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….







Excellent info. I a beginner to C# programming. Could you
Hui K. | January 17, 2007 | 8:33 amExcellent 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 amYour 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 pmThere’s a C# wrapper for Google Search API called GAPI.Net on CodePlex.