Program Google in C# and .NET

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

The Google Web APIs Developer’s Kit 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 that you would 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 #97] , form, too) to those in Perl Hack #98 ], et al.

Tip

Compiling and running this hack requires that you have the .NET Framework (http://msdn.microsoft.com/netframework/downloads/updates/default.aspx) installed.

The Code

Type this code and save it to a text file called googly.cs:

// 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, 2nd Edition 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.