180 likes | 349 Views
Google Web API. See: http://www.google.com/apis/. Concept:. With the Google Web APIs service, software developers can query more than 3 billion web documents directly from their own computer programs.
E N D
Google Web API See: http://www.google.com/apis/
Concept: • With the Google Web APIs service, software developers can query more than 3 billion web documents directly from their own computer programs. • Google uses the SOAP and WSDL standards so a developer can program in his or her favorite environment - such as Java, Perl, or Visual Studio .NET.
Google Web APIs provide three service: • Search relative web pages according to the keyword(s) user supplies • Return the cached web page to the user by the URL user supplies • Correct the spell of the word user inputs
Search Requests: • Search requests submit a query string and a set of parameters to the Google Web APIs service and receive in return a set of search results. Search results are derived from Google’s index of over 2 billion Web pages.
Search Results Format: • Search Response----Each time you issue a search request to the Google service, a response is returned to you. (We will describe the meanings of the values returned to you.) • Result Element
Search Response: <documentFiltering>--A Boolean value indicating whether filtering was performed on the search results <searchComments>--A text string intended for displaying to an end user <estimatedTotalResultsCount>--The estimated total number of results that exist for the query
Continue: • <estimatIsExact>--A Boolean value indicating that the estimate value is actually the exact value • <resultElements>--An array of <resultElement> items. This corresponds to the actual list of search results • <searchQuery>--This is the value of <Q> for the search request
Continue: • <startIndex>--Indicates the index (1-based) of the first search result in <resultElements> • <endIndex>--Indicates the index(1-based) of the last search result in <resultElements> • <searchTips>--A text string intended for displaying to the end user. It provides instructive suggestions on how to use Google
Continue: • <directoryCategories>--An array of <directoryCategory> items • <searchTime>--Text, floating-point number indicating the total server time to return the search results, measured in seconds
Cache Requests: • Cache requests submit a URL to the Google Web APIs service and receive in return the contents of the URL when Google’s crawlers last visited the page.
Spelling Requests: • Spelling requests submit a query to the Google Web APIs service and receive in return a suggested spell correction for the query (if available).
Java Implementation: • Google provides a java implementation of the Google Web APIs • We will take a look at it and provide an example finally.
The java classes: • com.google.soap.search.GoogleSearch • com.google.soap.search.GoogleSearchResult • com.google.soap.search.GoogleSearchResultElement • com.google.soap.search.GoogleSearchFault • com.google.soap.search.GoogleSearchDirectoryCategory
Usage Demo: • GoogleSearch s = new GoogleSearch(); • s.setKey(clientKey); • try { • if (directive.equalsIgnoreCase("search")) { • s.setQueryString(directiveArg); • GoogleSearchResult r = s.doSearch(); • System.out.println(r.toString()); • } else if (directive.equalsIgnoreCase("cached")) { • byte [] cachedBytes = s.doGetCachedPage(directiveArg); • String cachedString = new String(cachedBytes); • System.out.println(cachedString); • } else if (directive.equalsIgnoreCase("spell")) { • System.out.println("Spelling suggestion:"); • String suggestion = s.doSpellingSuggestion(directiveArg); • System.out.println(suggestion); • } • }
Example program: • You can download the executive files and source files of the example from Dr. Wang’s home page.