Google Ajax Search API

CSE 190 M (Web Programming), Spring 2007

University of Washington

References: homepage, code samples, API reference

Except where otherwise noted, the contents of this presentation are © Copyright 2007 Marty Stepp and are licensed under the Creative Commons Attribution 2.5 License.

Valid XHTML 1.0 Strict Valid CSS!

Javascript frameworks

Many groups have released Javascript frameworks you can include in your web pages to add effects:

What is the Google Ajax Web API?

Google code

API keys

<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key= ABQIAAAAjwpa3Lmr7L0oXrBemAIp0BSx0OSUw7R9ozDoChrVVXrbgKdJeBTWWRQkTwM5gxzSfgnTYruTJLircA" type="text/javascript"></script>

Ways of using the API

"Hello, World!" app

// in your window.onload handler:
var searchControl = new GSearchControl();
searchControl.addSearcher(new search());
searchControl.draw(document.getElementById("id"));
searchControl.execute("query");

Search control example

The search objects

search objectanalogous to
GwebSearch www.google.com
GlocalSearchlocal.google.com
GvideoSearchvideo.google.com
GblogSearch blogsearch.google.com
GnewsSearch news.google.com
GbookSearch books.google.com

Methods/properties common to all searches

Web search example

var search = new Search();
search.setSearchCompleteCallback(window, function() {
    for (var i = 0; i < search.results.length; i++) {
        do something with search.results[i];
    }
});
search.execute("query");
var search = new GwebSearch();
search.setSearchCompleteCallback(window, function() {
    for (var i = 0; i < search.results.length; i++) {
        alert(search.results[i].url);
    }
});
search.execute("miserable failure");

Web search: GwebSearch

Local search: GlocalSearch

Video search: GvideoSearch

Blog search: GblogSearch

News search: GnewsSearch

Book search: GbookSearch

Practice problem: Google Fight