Programming the Google Web API with C# and .NET

Create GUI and console Google search applications with C# and the .NET framework.

The Google Web APIs Developer’s Kit Section 5.4 includes a sample C# Visual Studio .NET (http://msdn.microsoft.com/vstudio/) project for a simple GUI Google search application (take a look in the dotnet/CSharp folder). The functional bits you’d probably find most interesting are in the Form1.cs code.

This hack provides basic code for a simple console Google search application similar in function (and, in the case of Java [Hack #56], form, too) to those in Perl [Hack #50], Python [Hack #57], et al.

Tip

Compiling and running this hack requires that you have the .NET Framework (http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28000519) installed.

The Code

// googly.cs // A Google Web API C# console application // Usage: googly.exe <query> // Copyright (c) 2002, Chris Sells. // No warranties extended. Use at your own risk. using System; class Googly { static void Main(string[] args) { // Your Google API developer's key string googleKey = "insert key here"; // Take the query from the command-line if( args.Length != 1 ) { Console.WriteLine("Usage: google.exe <query>"); return; } string query = args[0]; // Create a Google SOAP client proxy, generated by: // c:\> wsdl.exe http://api.google.com/GoogleSearch.wsdl GoogleSearchService googleSearch = new GoogleSearchService( ); // Query Google GoogleSearchResult results = googleSearch.doGoogleSearch(googleKey, ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.