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,
query, 0, 10, false, "", false, "", "latin1", "latin1");
// No results?
if( results.resultElements == null ) return;
// Loop through results.
foreach( ResultElement result in results.resultElements ) {
Console.WriteLine( );
Console.WriteLine(result.title);
Console.WriteLine(result.URL);
Console.WriteLine(result.snippet);
Console.WriteLine( );
}
}
}
Remember to insert your Google developer's key in
place of insert key here, like so:
// Your Google API developer's key.
string googleKey = "12BuCK13mY5h0E/34KN0cK@ttH3Do0R
";