Download presentation
Presentation is loading. Please wait.
1
Introduction to Google API… By Pratheepan Raveendranathan NLP Group Meeting 10/10/2003
2
The Google Web APIs service allows software developers to query more than 3 billion web documents directly from their own computer programs. Google uses the SOAP and WSDL standards to act as an interface between the user’s program and Google API. Programming environments such as Java, Perl, Visual Studio.NET are compatible with Google API. Definitions from http:// www.google.com/apis/ What is Google API?
3
SOAP and WSDL SOAP: Simple Object Access Protocol WSDL: Web Services Description Language
4
Google API for Perl SOAP:Lite Lite for Perl is a collection of Perl modules which provides a simple and lightweight interface to the SOAP both on client and server side. Sample Program: use SOAP::Lite; my $key='000000000000000000000000'; my $query="foo"; my $googleSearch = SOAP::Lite -> service("file:GoogleSearch.wsdl"); my $result = $googleSearch -> doGoogleSearch($key, $query, 0, 10,"false", "", $ print "About $result->{'estimatedTotalResultsCount'} results.\n";
5
Google API for Java Google APi for Java is similar to Google API for Perl. Uses the SOAP module to interact with Google API
6
Google API & Java package com.google.soap.search; import com.google.soap.search.GoogleSearch; import com.google.soap.search.GoogleSearchFault; import java.io.*; public class GoogleAPIDemo { public static void main(String[] args) { // Parse the command line if (args.length != 3) { printUsageAndExit(); } String clientKey = args[0]; String directiveArg = args[2]; // Report the arguments received System.out.println("Parameters:"); System.out.println("Client key = " + clientKey); System.out.println("Directive = " + directive); System.out.println("Args = " + directiveArg); // Create a Google Search object, set our authorization key GoogleSearch s = new GoogleSearch(); s.setKey(clientKey);
7
// Depending on user input, do search or cache query, then print out result try { if (directive.equalsIgnoreCase("search")) { s.setQueryString(directiveArg); GoogleSearchResult r = s.doSearch(); System.out.println("Google Search Results:"); System.out.println("======================"); System.out.println(r.toString()); } else if (directive.equalsIgnoreCase("cached")) { System.out.println("Cached page:"); System.out.println("============"); byte [] cachedBytes = s.doGetCachedPage(directiveArg); // Note - this conversion to String should be done with reference // to the encoding of the cached page, but we don't do that here. String cachedString = new String(cachedBytes); System.out.println(new String(pageText)); System.out.println(cachedString); } else if (directive.equalsIgnoreCase("spell")) { System.out.println("Spelling suggestion:"); String suggestion = s.doSpellingSuggestion(directiveArg); System.out.println(suggestion); }
8
Results [ URL = "http://www.ci.duluth.mn.us/" Title = "City of Duluth Official Webpage" Snippet = "Business in Duluth, It's summer in Duluth.... Check our Parks & Recreation pages for summer events. Visit Duluth, Comprehensive Plan.... " Directory Category = {SE="", FVN=""} Directory Title = "" Summary = "" Cached Size = "22k" Related information present = true Host Name = "" ],
9
Spell Suggestion Query: java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo iROSyfxQFHKjtA1CLcVQ3aGawqQW2j2Q spell Dulut Result: Parameters: Client key = iROSyfxQFHKjtA1CLcVQ3aGawqQW2j2Q Directive = spell Args = Dulut Spelling suggestion: Duluth
10
Cached Query java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo iROSyfxQFHKjtA1CLcVQ3aGawqQW2j2Q cached www.d.umn.edu/~tpedersewww.d.umn.edu/~tpederse Result: Registry of Latin American Researchers in NLP and CL Visit the Registry! My Site of the Month <img src="http://teach-computers.org/images/omwe_link1.gif" alt="Open Mind word game" width="200" height="65" border="1">
11
Some Ideas… Duluth AND Vacation VS Hawaii and Vacation NEAR Operator in Alta Vista Positive & Negative inference beauty NEAR excellent beauty NEAR bad
12
Problems Limit of 1000 queries a day. Google Web APIs service is a beta web program: meaning Google does not guarantee the availability of the service One account per user.
13
Conclusion…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.