Mining Google Web Services: Building Applications with the Google API
Older versions of the Palm and most cellular telephones are so limited in processing capacity and memory that you really won't want to try to create a local Google Web Services application for them. The best alternative is to create a Web application that retrieves and formats the data for the device before passing it along. This example relies on a special ASP.NET application specifically designed for mobile devices. The server detects the device type and pages forms as needed to ensure each form appears correctly on the device.
Tip | Many developers wrongly assume that cellular telephones will remain limited devices. Many companies are working on advanced versions that will let users perform some advanced tasks . For example, Cisco recently released an IP cellular telephone with XML support. This device could allow a user full access to Google from any location. Read more about this new cellular telephone at http://www.eweek.com/article2/0,4149,1259848,00.asp. In addition, at least one company is working with Microsoft to include the Windows Mobile 2003 operating system in a cellular telephone (see the Computerworld story at http://www.computerworld.com/mobiletopics/mobile/story/0,10801,84923,00.html). |
Listing 9.3: Creating a Web-based Google Web Services Application
|
private void btnSubmit_Click(object sender, System.EventArgs e) { GoogleSearchService Service; // Search service routine access. GoogleSearchResult Result; // All of the results. ResultElement[] Items; // All of the search items. StringBuilder SB; // Contains the output data. // Create the search service. Service = new GoogleSearchService(); // Make the call. Result = Service.doGoogleSearch(txtLicense.Text, txtKey.Text, Convert.ToInt32(txtIndex.Text), Convert.ToInt32(txtResults.Text), false, "", false, "", "", ""); // Update the index. txtIndex.Text = Convert.ToString(Result.endIndex); // Process the result elements. Items = Result.resultElements; foreach (ResultElement Item in Items) { // Blank the StringBuilder. SB = new StringBuilder(); // Add the data to the row. SB.Append(StringToText(Item.title)); SB.Append(" - "); SB.Append(Item.URL); // Add the data to the list. lstOutput.Items.Add(SB.ToString()); } // Show the form. this.ActiveForm = Results; }
|
The code begins as usual by creating a GoogleSearchService object. In this case, the variable doGoogleSearch() arguments are limited to the license, search phrase, starting index, and number of results. In a production application, you would probably hard code the license value for the user or make it configurable through a dialog box. The idea is to keep the number of entries small because the screen real estate is limited. In addition, all of the entries have default values. You don't want to force the user to type any more information than needed. One configuration option for this application should be a default search so the user can modify it as needed (or use it as presented on screen).
The application output is also very simple. The code places the data in a StringBuilder object, and then places this object in a list box. This is one case where you might want to limit the user to less than 10 entries. Experimentation shows that you can get four entries at most on a screen if you include the page title. It's possible to get up to eight short URLs on a screen, but they have to be very short. A good alternative, in this case, is to present the URLs one page at a time. Figure 9.11 shows typical output from this application.