Chapter 39. Exploring the Future of Google

<feature><title>In This Chapter</title>
  • Learning how to enhance your Web site using Google Maps, Webmaster tools, and the Google AJAX Search code

  • Reaching Google users by creating clever Google Gadgets and by enhancing the Google Toolbar with your custom button

  • Integrating Google into your Web and desktop applications

  • Searching through public Open Source code to find useful code for your applications

</feature>

Number 10 of Google’s “Ten things Google has found to be true” is “Great just isn’t good enough.” If that’s not incentive enough to drive innovation, nothing is. Google’s goal of building a better search engine led it to learn, listen, and pay attention to the user. And from that, to innovate. The folks at Google have come a long way since building the best search engine, and Google innovation now includes communications in the form of e-mail, chatting, and blogging; entertainment like Google Videos, News, Mapping, and Web publishing; and office automation tools such as Google Docs. I would be remiss in leaving out everyone’s favorite, Google Earth.

Part of the Google goal of not being evil sets the tone and direction for its software development and interaction with users. This chapter explores some of the ways Google works with software developers and partner companies to continue innovation. This chapter introduces many of the Google programming technologies that allow you to integrate your Web site or Internet-ready application with Google services and applications.

Find Google’s Ten things at www.google.com/corporate/tenthings.html.

Note

This chapter is geared toward the more advanced Web developer and software programmer.

Software Development

Google has taken every precaution to remain a principled software development company devoted to the cause of ethical behavior and Open software development. Part of its efforts to maintain this way of doing business is to create a set of software development principles and participate fully in allowing others access to its code and by developing software development APIs to simplify interacting with Google programs.

Principles

Google worries about what it perceives to be evil trends in software development and has therefore created a set of broad software development principles. Google means to follow these principles in its own software development and hopes that others in the software industry will adopt them out of ethical concern for the end user. In brief, these principles are:

  • Software should not trick you into installing it.

  • When you install software, it should tell you its purpose or function, and if it makes money through ads, you should know that, too.

  • Software should be easy to delete or disable.

  • Software should not make secret changes to other installed programs, and the software user interface should not try to trick you.

  • You should be asked before a software product can collect and transmit personal information.

  • Software applications that meet these guidelines should not be bundled with software that does not.

You can join the software “Neighborhood Watch” by visiting www.stopbadware.org, the Web site for an independent group formed to fight malicious software.

Enhancing Your Web Site

Get started enhancing your Web site with the tools and application programming interfaces (API) found at http://code.google.com. Build Web services, create full applications that talk to Google services, and interact with your users by building gadgets or custom Google Toolbar buttons (my personal favorite).

Google Maps API

Your Web site can use the power of Google Maps to show people how to find you, the way to the family picnic, or your favorite historic sites. The Google Maps API lets you use JavaScript to embed a Google map right in your own Web page. You can additionally customize the map using markers, polylines, and shadowed information windows.

You need a key to get started. You can apply for your key at www.google.com/apis/maps/. Click the Sign up for a Google Maps API key link at the top of the page.

Each key you sign up for is good only for a single directory on your site. This means that if you have a directory at www.mysite.com/contact, then this key is good for all pages found in the contact directory. If you have a second directory that needs the Google Maps API, such as www.mysite.com/birdmigrations, then you need a second key.

There are no limits to the number of requests your site can make to Google Maps for a map display, but there is a limit to the number of geocode (address location) requests to 50,000 requests per day.

You’ll be happy to know that the Google Maps API does not include advertising. Along the same lines, Google does not allow you to charge others to view these maps. If you have an application for the maps and want to charge, check out Chapter 37.

After you sign up for your API key, Google provides a sample Web page to get started. Figure 39.1 shows you the sample, modified to show the Orchidland area on the Big Island of Hawaii. If you are unsure of your latitude and longitude, try using Google Earth. The API uses a different format for latitude and longitude than the values Google Earth displays. The U.S. government to the rescue! Point your Web browser here: www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html.

Modify the sample code to get started with maps quickly.

Figure 39.1. Modify the sample code to get started with maps quickly.

The FCC has a simple converter you can use. Here is the sample code used to generate Figure 39.1:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-
8"/>
    <title>Map to our house on Oliana Street</title>
    <script

src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIA...
QChi6Cg"
      type="text/javascript"></script>
    <script type="text/javascript">

    //<![CDATA[

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(19.58277, -155.0395), 13);
        map.addOverlay(new GMarker(19.58277, -155.0395));
      }
    }

    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 500px; height: 300px"></div>
  </body>

Note

The key in the previous example was modified for security reasons. Your key will be much longer.

Google Webmaster Tools

Google’s Webmaster Central is a hub of information for Web developers. There are links to the Site Status Wizard to learn whether your site has been indexed. There is a link to the Webmaster tools, commonly known as Sitemaps. You can also learn more about submitting information to Google Base and the Book Search. Most important, you can stay on top of current Google developer information by subscribing to the Google blog for Webmasters and join the Google Group for Webmasters. You also may find the Webmaster help center useful. To find Webmaster Central, point your Web browser to www.google.com/webmasters/.

When you use Google’s Sitemap tool, you can add a list of your Web sites and use the Google Webmaster tools. Log in to your Google account and navigate to www.google.com/webmasters/sitemaps/siteoverview.

In the upper-right corner of this Web page, you see a + Tools link, where you can do these things:

  • Download data for all your sites

  • Report spam in the Google Index

  • Submit a reinclusion request

Additionally, you can see crawl stats, query stats, page analysis, and index stats by clicking the Statistics tab. If your site is having problems getting indexed, click the Diagnostics tab for help in determining the probable cause of indexing problems. There could be problems with a robots.txt file or any number of other problems.

Google Web Toolkit

If you’ve seen the pages where portions of the page update without reloading the entire page, like Google Maps, you’re looking at an application written in AJAX, sort of Javascript on steroids. The Google Web Toolkit lets you build powerful front ends to your Web site using the Java programming language and the Google Web Toolkit framework. Then the Google Web Toolkit (GWT) compiler converts the Java classes into Javascript and HTML.

When developing your application in Java, you use the GWT user interface components known as widgets. Combine the widgets on traditional Java panels. Here is sample button code that launches a window alert:

public class MyButton implements EntryPoint {
  public void onModuleLoad() {
    Button btn = new Button("I am a button", new ClickListener() {
      public void onClick(Widget sender) {
        Window.alert("I have been clicked");
      }
    });
    RootPanel.get().add(btn);
  }
}

There are two modes in which your Google Web Toolkit application can run: Hosted mode and Web mode. Hosted mode applications are run as Java and use the Java Virtual Machine. Web mode applications are converted to Javascript using the GWT compiler and run strictly as Javascript and HTML; no Java is included in the page.

For more information and detailed instructions on using the GWT, visit code.google.com/ webtoolkit/overview.html.

Google AJAX search API

Now that you know a little about AJAX, you’ll be happy to know that Google has made it easier to build applications on top of the Google Search technology. The Google AJAX search API also helps you add dynamic search boxes for Google Web, Video, News, Maps, and Blog search results.

As with the Google Maps API, you need to have Google generate a key. Point your Web browser to http://code.google.com/apis/ajaxsearch/.

Click the Sign up for a Google AJAX Search API key link. Agree to the license agreement, and type the URL that will host the AJAX Search code. Then click Generate API Key. Also like the Google Maps API, Google provides you a sample page, with the results shown in Figure 39.2:

<!DOCTYPE html PUBLIC "-
//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml
1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-
8"/>
    <title>My Google AJAX Search API Application</title>
    <link href="http://www.google.com/uds/css/gsearch.css" type="text/c
ss" rel="stylesheet"/>
    <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;am
p;key=ABQdaX_wm1K-
Q6KdSr5G7WhQDZiGdv9tL82_8S5e2Pd_QChi6Cg" type="text/javascript"></scrip
t>
    <script language="Javascript" type="text/javascript">
    //<![CDATA[
    function OnLoad() {
      // Create a search control
      var searchControl = new GSearchControl();

      // Add in a full set of searchers
      var localSearch = new GlocalSearch();
      searchControl.addSearcher(localSearch);
      searchControl.addSearcher(new GwebSearch());
      searchControl.addSearcher(new GvideoSearch());
      searchControl.addSearcher(new GblogSearch());

      // Set the Local Search center point
      localSearch.setCenterPoint("New York, NY");

      // Tell the searcher to draw itself and tell it where to attach
      searchControl.draw(document.getElementById("searchcontrol"));

      // Execute an initial search
      searchControl.execute("Google");
    }

    //]]>
    </script>
  </head>
  <body onload="OnLoad()">
    <div id="searchcontrol"/>
  </body>
</html>
Place the dynamic Google Search anywhere on your Web page.

Figure 39.2. Place the dynamic Google Search anywhere on your Web page.

Note

The key in the code above has been abbreviated for security reasons. Google will create this same sample for you with a key that works on your own Web site.

You will find the complete documentation for this API at http://code.google.com/apis/ajaxsearch/documentation/.

Reaching Google Users

One quick way to reach Google users is to write Google Gadgets that they can use on their home pages or their Google Desktops. It’s a fun and simple way to interact with others. Another simple thing you can do is to create custom buttons for the Google Toolbar. Create fun buttons that point to your home page and trade them with your friends.

Write your own Google Gadgets

You can write two types of Google Gadgets: Universal Gadgets and Desktop Gadgets. The Universal Gadget sounds like the perfect tool for any toolbox. Though it’s up to you to build one, the Universal Gadget can be plopped onto any Google Home page (http://pages.google.com), Google Desktop, Blogger blogs, or even your Web page hosted somewhere other than GooglePages.

The Desktop Gadget works with Google Desktop and can run on your desktop after you install Google Desktop. Read more about personalizing Google Desktop in Chapter 11.

Building Universal Google Gadgets is fairly simple compared to the other API technologies in this chapter. You won’t have to download anything, and there are no API libraries to learn about. You can write a Google Gadget using simple HTML, or if you want to get fancy, you can use Javascript. One downside to a Universal Gadget is that you must be online for it to work. If you need a gadget that works offline, try a Desktop Gadget.

The Desktop Gadget has a bit more flexibility. Even though it works only with Google Desktop, it runs even when you are not connected to the Internet. Google Desktop Gadgets also can interact with other desktop applications. For example, have your gadget interact when someone starts writing an e-mail message. Your gadget could create boilerplate e-mail messages for you. You can write Desktop Gadgets using Javascript, as with the Universal Gadget, or the C and C++ programming languages, as well as the newer Microsoft .NET languages, C#, and VB.Net. You need to download the software developer’s kit (SDK) in order to develop Desktop Gadgets.

To get started developing Desktop Gadgets download the SDK at desktop.google.com/developer.html.

Google Toolbar API

You can create custom buttons that can be added to the Google Toolbar. These buttons can have custom navigation, search, send, and update capabilities. Custom buttons can be represented as an icon, a drop-down list of icons, or text strings, any of which can be updated by an RSS feed. A custom button can have a tooltip when the mouse hovers over it and an optional title that appears next to the button. This is particularly useful for drop-down buttons.

To make your button functional, you can save important preferences in an XML file. These preferences include such things as a URL you want to have the user navigate to when the button is clicked and URLs that include search parameters or text parameters that send important parameters to the Web site. You also can include an update URL where updates to the button can be obtained.

To create and install a custom button, first create an XML file that defines the button’s important information:

<?xml version="1.0" encoding="utf-8"?>
<custombuttons xmlns="http://toolbar.google.com/custombuttons/">
  <button>
    <site>http://www.tedcoombs.com</site>
  </button>
</custombuttons>

You can create custom icons for your new button in a number of different graphic formats. Before you can use it in the Google Toolbar, it needs to be converted to Base 64 ASCII text. Base 64 what? Luckily, this Web site can do that for you: www.motobit.com/util/base64-decoder-encoder.asp.

Simply browse for your file on your computer, and the file is uploaded and encoded for you. Copy and paste the text it creates into your XML file surrounded by an <icon> element like this:

<icon mode="base64" type="image/x-icon">
/9j/4AAQSkZJRgABAgEAtAC0AAD/4QOuRXhpZgAATU0AKgAAAAgABwESAAMAAA
ABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAc
gEyAAIAAAAUAAAAhodpAAQAAAABAAAAnAAAA
</icon>

In reality, the text between the begin and end <icon> elements will be much greater than the sample above. To do this quickly and easily, take your favorite picture. Open it in a program like Photoshop. Shrink the image down to 16x16 pixels, and save it. Then upload it into the encoder, copy the text into your XML file with icon elements, and you’re golden.

Note

The custom button feature currently works only with Internet Explorer.

Integrating with Google

You can build powerful applications that manage Google services such as AdWords. You no longer need to use the AdWords Web management interface. You can build your own application that makes calls into the AdWords service. The Google Data API takes ATOM and RSS to the next level. Find out how to use the GData protocol to create enhanced syndication applications. Create powerful e-commerce applications using the Google Checkout API.

Google AdWords API

The Google AdWords API provides nine basic services that allow you to build powerful AdWords maintenance applications. To get started using the AdWords API, you must first sign up to receive a special token that is included in each of your AdWords API calls to identify you. To receive your token, point your Web browser to www.google.com/apis/adwords/.

Sign in to the AdWords API center, or sign up by clicking the links in the blue box in the upper-right corner of the AdWords API page.

Your applications can do everything from creating new AdWords accounts to listing the performance of certain keywords. The messaging technology used is XML-based technology known as SOAP. Using the AdWords API, you build Web service clients that provide the following services:

  • Account Service: Create and modify Google AdWords accounts.

  • Campaign Service: Create, list, and modify your campaigns including setting the campaign name, its daily budget, and the end date.

  • AdGroup Service: Create and list ad groups, associate ad groups with a campaign, and perform related actions.

  • Keyword Service: Access, modify, and create keywords in an AdGroup.

  • Criterion Service: Create and modify keyword and Web site targeting criteria. You can get the keywords for a keyword-targeted campaign or the Web sites for site-targeted campaigns.

  • Keyword Tool Service: Generate keywords based on a seed keyword or on the words found on a specific Web page or Web site.

  • Creative Service: This lets you create and modify creatives and associate them with an ad group.

  • Traffic Estimator Service: This lets you estimate data, such as the cost per click (CPC), click-through rate (CTR), and average position of your ads.

  • Report Service: Get reports on ad impressions, clicks, and click-through rate.

  • Info Service: This provides basic data regarding the AdWords API usage.

Note

All the AdWords API calls are sent encrypted using SSL for security purposes.

Visit the AdWords API blog at http://adwordsapi.blogspot.com.

Google Data API

The Google Data API, more commonly called GData, is an XML protocol based on, and extending, the Atom 1.0 and RSS 2.0 syndication protocols. If you need to refresh your memory, you can find more information about ATOM and RSS in Chapter 14.

GData extends these two syndication protocols in a number of ways. For example, neither the ATOM nor the RSS protocol has query ability, while the GData protocol allows queries to be sent. It just wouldn’t be Google without search capability.

The GData protocol also allows for authentication, updates, and something known as optimistic concurrency. For those familiar with database updating, this is similar to transactions. It makes certain that if one person is changing information, and another person changes the information before the first person does, any updates based on the old information are denied.

The authentication preferred by Google when using the GData protocol is known as Authentication for Installed Applications, a Google-specific authentication mechanism. Third-party front-end applications to a GData service should use an authentication mechanism known as Account Authentication Proxy for Web-based Applications.

Session state (the current state of all application variables) is managed in two ways by Google: one through the use of cookies, and the other by sending a query parameter in the URL. It’s recommended that your GData application support one of these two methods of maintaining the session state. Your application still works if you don’t maintain session state, but two round trips to the server are required, which is less efficient.

For the full GData documentation, visit http://code.google.com/apis/gdata/protocol.html.

Google Checkout API

Integrate Google Checkout into your e-commerce Web site to enable customers to easily check out by paying with their credit cards. Your account is automatically updated with their purchases.

Your E-commerce checkout pages host a Google Checkout button. Users click this button, and they see a signup or signin page. When users already have a Google account set up with their payment information, they can simply sign in and continue with their checkout. New users can easily sign up. What your users see is shown in Figure 39.3.

Sign up for a Google Checkout account for easy checkout at Google-enabled sites.

Figure 39.3. Sign up for a Google Checkout account for easy checkout at Google-enabled sites.

The shopper on your site then sees his order detail and can click Place your order now. When checkout is complete, he is thanked for his order and an e-mail copy of the receipt is sent.

You must first sign up for a Google Merchant account. By doing this, you ask Google to process credit card transactions on your behalf, and this is not a free service. As of the writing of this book, you can discount your fees to Google by using an AdWords account; otherwise, each transaction is a percentage of the total sale plus a small pertransaction fee. After logging in to Google, find the current rate at https://checkout.google.com/seller/fees.html.

Signing up for the account is easy. Type a little information about your business Web site, your policies regarding refunds, and your financial information. After you sign up for your Google Merchant account, and are approved, you receive a Merchant ID and a Merchant Key. These are used to identify your transactions and allow you to communicate with Google.

After you have a Google Merchant account, the first step is to begin integrating the Checkout API XML into your shopping cart code. The second step is including a Web service that sends and receives XML messages.

Note

Google Checkout works with AdWords by displaying a special Google Checkout icon in your ad, letting people know that you want them to spend money on your site (and you use Google Checkout).

Get all the technical documentation for using and integrating the Google Checkout API at http://code.google.com/apis/checkout/developer/index.html.

Google Talk XMPP and Jingle

When you want to create your own client application that talks to the Google Talk service, you need to understand the XMPP protocol in order to program the new client application. The Google Talk service uses an open communications protocol known as the eXtensible Messaging and Presence Protocol. In 1999, Jeremie Miller announced the existence of Jabber, which was an open technology for instant messaging and presence. This later formalized as (IETF) RFC 3920 – RFC 3923. Google has extended XMPP for its own purposes, and documentation for those extensions can be found at http://code.google.com/apis/talk/jep_extensions/extensions.html.

The features in this protocol include:

  • Instant messaging

  • Presence (anybody home?)

  • Media negotiation

  • Whiteboarding

  • Collaboration

  • Lightweight middleware

  • Content syndication

  • Generalized XML delivery

Google Talk also uses a set of XMPP extensions called Jingle. These extensions allow for the creation and maintenance of peer-to-peer communications between clients. This is useful for functionality such as peer-to-peer file sharing or video chatting. When writing your application in C++, a set of C++ components called Libjingle is provided by Google. Use these components to implement Google’s version of Jingle and Jingle Audio for voice communications. Download Libjingle from SourceForge at http://sourceforge.net/projects/libjingle/.

Note

Libjingle components are offered free under a BSD license agreement.

For more information about XMPP, visit www.xmpp.org.

Google Code Search

Google Code Search is not an API or a protocol, but because this chapter is primarily for programmers and Web developers, the Google Code Search is of particular interest. Search through public source code by launching Google Code Search at www.google.com/codesearch, shown in Figure 39.4.

Search through public Open Source code using Google Code Search.

Figure 39.4. Search through public Open Source code using Google Code Search.

Search using the Code Search box by typing regular expressions, search strings, special search operators, or a combination of these three. The operators are included in Table 39.1.

Table 39.1. Google Code Search Operators

Operator

Description

file: regexp

Search in files matching the regular expression (regexp). For example, file:*jin.c*.

package: regexp

Search in packages identified by the regular expression. For example, package:perl MyFile.

lang: regexp

Search only for code written in a particular programming language. For example, lang:”c++”.

license: regexp

Search only for code protected by a particular type of license. For example, license:gpl.

Figure 39.5 shows the result of a very broad search for all public source code covered under the GPL license. The result includes a code snippet, a link to identical code found in other sources, a link to the actual source code archive, and a link to the license agreement. When the same code is found in several places within a single code source, you see a link to the other locations by clicking the More from link.

See code snippets and links to the license agreements.

Figure 39.5. See code snippets and links to the license agreements.

Summary

This chapter provided an introduction into the many ways to interface with, integrate, talk to, and otherwise use Google technologies in your Web and desktop applications. You can create your own Google Talk client or use the Google Checkout in your e-commerce Web applications. Google has attempted to make interfacing with its technologies as simple as possible by creating programming APIs and by using standard open protocols. For additional information on these and other Open Source projects or just to see a list of Open Source programming projects at Google, visit http://code.google.com/projects.html. With this foundation for innovation, it’s no wonder that the Google Laboratories are full of upcoming and interesting projects, which are discussed in the next and final chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.35.122