Google Web API See http www google comapis
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.
Seach Request Format: Name Description Key Provided by Google, Google uses the key for authentication and logging Query string Q start max. Res ults Zero-based index of the first desired result Number of results desired per query. The maximum value per query is 10. (see next page)
filter Activates or deactivates automatic results filtering, which hides very similar results and results that all come from the same Web host. restrict Restricts the search to a subset of the Google Web index, such as a topic like “Linux”. safe. Se A Boolean value which enables filtering of arch adult content in the search results. lr Language Restrict-Restricts the search to documents within one or more languages.
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: <document. Filtering>--A Boolean value indicating whether filtering was performed on the search results <search. Comments>--A text string intended for displaying to an end user <estimated. Total. Results. Count>--The estimated total number of results that exist for the query
Continue: • <estimat. Is. Exact>--A Boolean value indicating that the estimate value is actually the exact value • <result. Elements>--An array of <result. Element> items. This corresponds to the actual list of search results • <search. Query>--This is the value of <Q> for the search request
Continue: • <start. Index>--Indicates the index (1 -based) of the first search result in <result. Elements> • <end. Index>--Indicates the index(1 -based) of the last search result in <result. Elements> • <search. Tips>--A text string intended for displaying to the end user. It provides instructive suggestions on how to use Google
Continue: • <directory. Categories>--An array of <directory. Category> items • <search. Time>--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. Google. Search. Re sult. Element • com. google. soap. search. Google. Search. Fa ult • com. google. soap. search. Google. Search. Dir ectory. Category
Usage Demo: • • Google. Search s = new Google. Search(); s. set. Key(client. Key); • • • • try { if (directive. equals. Ignore. Case("search")) { s. set. Query. String(directive. Arg); Google. Search. Result r = s. do. Search(); System. out. println(r. to. String()); } else if (directive. equals. Ignore. Case("cached")) { byte [] cached. Bytes = s. do. Get. Cached. Page(directive. Arg); String cached. String = new String(cached. Bytes); System. out. println(cached. String); } else if (directive. equals. Ignore. Case("spell")) { System. out. println("Spelling suggestion: "); String suggestion = s. do. Spelling. Suggestion(directive. Arg); System. out. println(suggestion); } }
Example program: • You can download the executive files and source files of the example from Dr. Wang’s home page.
- Slides: 17