64
Using the Google AJAX APIs Chris Schalk 10/1/2008

Using the Google AJAX APIs

Embed Size (px)

DESCRIPTION

This is a presentation on Google's AJAX APIs that I gave to the Silicon Valley Google Technology User Group

Citation preview

Page 1: Using the Google AJAX APIs

Using the Google AJAX APIsChris Schalk10/1/2008

Page 2: Using the Google AJAX APIs

2 (c)2008 Google

Agenda

• The core Google AJAX APIs

– Google AJAX Search API

– Google AJAX Feed API

– Google AJAX Language API

• Demo review: Some cool externally developed demos

• AjaxSearch Java Demo

• How the AJAX APIs are more than fluff to spice up aWeb page: Examining an application built w/ the APIs

– Utilize the Raw AJAX APIs and advanced features

– Show how Reader and Google CSE are utilized

– How to wrap the application as a gadget

Page 3: Using the Google AJAX APIs

3 (c)2008 Google

Agenda

• The core Google AJAX APIs

– Google AJAX Search API

– Google AJAX Feed API

– Google AJAX Language API

• Demo review: Some cool externally developed demos

• AjaxSearch Java Demo

• How the AJAX APIs are more than fluff to spice up aWeb page: Examining an application built w/ the APIs

– Utilize the Raw AJAX APIs and advanced features

– Show how Reader and Google CSE are utilized

– How to wrap the application as a gadget

Page 4: Using the Google AJAX APIs

4 (c)2008 Google

The Basic Building Blocks

• HTML/DOM

• CSS

• Javascript

• Tools

– Editor

– Debugger - Firebug

– Performance - YSlow

• The Google AJAX Apis

– Search

– Feed

– Language

• Google Reader (www.google.com/reader)

• Google Custom Search Engines (www.google.com/cse)

• iGoogle

Page 5: Using the Google AJAX APIs

5 (c)2008 Google

Google AJAX APIs

Delivering the Web to Your Applications (Search, Feeds, Language)

AJAX APIs

• RESTful data access layer

–JSON/JSON-P

• JavaScript Runtime

–Designed for ease of use

• JavaScript Controls and UI elements

–Custom integration and styling

Page 6: Using the Google AJAX APIs

6 (c)2008 Google

Google AJAX APIs Background

• Comprehensive access to Google Systems (Search, Feeds,Language)

• End to end API stack:

– Data Access via JavaScript Methods and REST

– Built in Native UI and Large Suite of Advanced Controls

• Large, diverse customer base– Sites: Long Tail and Short Tail Sites (100 pv/d – 10m+ pv/d)

– Developers: Pro Web Developers – Scripters – Bloggers

• High Speed, Low Latency, Globally Available

Page 7: Using the Google AJAX APIs

7 (c)2008 Google

Google AJAX APIs Architecture

RESTful Data Access Layer

JavaScript Runtime Layer

JavaScript Controls and UI elements

AJAXAPIs

Page 8: Using the Google AJAX APIs

8 (c)2008 Google

Google AJAX APIs Architecture

RESTful Data Access Layer

JavaScript Runtime Layer

JavaScript Controls and UI elements

AJAXAPIs

Page 9: Using the Google AJAX APIs

9 (c)2008 Google

Google AJAX APIs Architecture

RESTful Data Access LayerAJAXAPIs

• Command Line Access• Server-to-Server Access• Non-JavaScript• JSON output

Page 10: Using the Google AJAX APIs

10 (c)2008 Google

Google AJAX APIs Architecture

AJAXAPIs

• Low level JavaScript Access• Allows for maximum UI flexibility• Requires custom coding• JSON parsing not needed

JavaScript Runtime Layer

Page 11: Using the Google AJAX APIs

11 (c)2008 Google

Google AJAX APIs Architecture

AJAXAPIs

• Minimal JavaScript needed• Least code required• No custom coding needed• UI control renders itself

JavaScript Controls and UI elements

Page 12: Using the Google AJAX APIs

12 (c)2008 Google

Google AJAX Search API

Multiple Search types available:

– Web

– Video

– News

– Image

– Local

– Book

– Blog

– Patent

Page 13: Using the Google AJAX APIs

13

Demo - Trying out the AJAX Search API

Page 14: Using the Google AJAX APIs

14 (c)2008 Google

Google AJAX Feed API

• Load

• Find

• Lookup

Page 15: Using the Google AJAX APIs

15

Demo - Using the Ajax Feed API1. Basic stuff

2. Mashup with Google Maps and Flickr

Page 16: Using the Google AJAX APIs

16 (c)2008 Google

Google AJAX Language API

• Translation

• Language Detection

Page 17: Using the Google AJAX APIs

17

Demo - Using the AJAX LanguageTranslation API

Page 18: Using the Google AJAX APIs

18 (c)2008 Google

Agenda

• The core Google AJAX APIs

– Google AJAX Search API

– Google AJAX Feed API

– Google AJAX Language API

• Demo review: Some cool externally developed demos

• AjaxSearch Java Demo

• How the AJAX APIs are more than fluff to spice up aWeb page: Examining an application built w/ the APIs

– Utilize the Raw AJAX APIs and advanced features

– Show how Reader and Google CSE are utilized

– How to wrap the application as a gadget

Page 19: Using the Google AJAX APIs

19 (c)2008 Google

Some notable AJAX APIs Applications

Time - AJAX Search API (news)http://www.time.com/time/politicshttp://www.time.com/time/global_business/united-states

NYTimes - AJAX Feed APIhttp://thecaucus.blogs.nytimes.com

People - AJAX Feed API + gadgetshttp://www.people.com/people/news/0,,,00.htmlhttp://www.google.com/uds/gadgets/people_ads/people_ads.html

SnowCovered - AJAX Language APIhttp://www.snowcovered.com/Snowcovered2/

Walkscore - AJAX Search API (local) + Maps APIhttp://www.walkscore.com/get-score.php?street=1600+amphitheatre+parkway+94043&go=Gohttp://www.walkscore.com/rankings/San_Francisco

Google Elections apps:http://www.google.com/2008election/http://www.google.com/2008election/convention.html

Background:http://www.searchmashups.blogspot.com/

Page 20: Using the Google AJAX APIs

20 (c)2008 Google

Agenda

• The core Google AJAX APIs

– Google AJAX Search API

– Google AJAX Feed API

– Google AJAX Language API

• Demo review: Some cool externally developed demos

• AjaxSearch Java Demo

• How the AJAX APIs are more than fluff to spice up aWeb page: Examining an application built w/ the APIs

– Utilize the Raw AJAX APIs and advanced features

– Show how Reader and Google CSE are utilized

– How to wrap the application as a gadget

Page 21: Using the Google AJAX APIs

21

Demo - Using AJAX Search with Java

Page 22: Using the Google AJAX APIs

22 (c)2008 Google

Are the AJAX APIs just used to spice up Web pages?

Answer: No!

Let’s examine a real application built byGoogle that use the Google AJAX APIs.

Page 23: Using the Google AJAX APIs

23 (c)2008 Google

Agenda

• The core Google AJAX APIs

– Google AJAX Search API

– Google AJAX Feed API

– Google AJAX Language API

• Demo review: Some cool externally developed demos

• AjaxSearch Java Demo

• How the AJAX APIs are more than fluff to spice up aWeb page: Examining an application built w/ the APIs

– Utilize the Raw AJAX APIs and advanced features

– Show how Reader and Google CSE are utilized

– How to wrap the application as a gadget

Page 24: Using the Google AJAX APIs

24 (c)2008 Google

The Official Google Blogs Application

Page 25: Using the Google AJAX APIs

Demo - Checking out the Google BlogsApplication

Page 26: Using the Google AJAX APIs

26 (c)2008 Google

What we saw

• The tag cloud view

• A detail entry/snippet view

• The hierarchical blog view

• Search control and results

• Translation capabilities

Page 27: Using the Google AJAX APIs

27 (c)2008 Google

How was this built?

• Building Blocks

– Google Reader (content feeds)

– Custom Search Engine

– AJAX APIs (Feed, Search, Language)

• Getting Started

– Build standalone HTML/CSS/JS

– google.load()

– google.setOnLoadCallback()

• Putting it all together

– Application details

• Making an iGoogle Gadget

– Wrapping things into iGoogle

Page 28: Using the Google AJAX APIs

28 (c)2008 Google

Building The Application

• Subscriptions

– Blog management

• Tags

– Grouping Subscriptions/Blogs

– Tag based pages

– Tag based feeds

• Tag Cloud

– All blogs top 20

• Hierarchical View

– All categorized blogs

Building Blocks - Google Reader - www.google.com/reader

Page 29: Using the Google AJAX APIs

29 (c)2008 Google

Building The Application

Building Blocks - Google Reader - www.google.com/reader

Tags and Categorization

Page 30: Using the Google AJAX APIs

30 (c)2008 Google

Building The Application

Building Blocks - Google Reader - www.google.com/reader

Tags and Sharing Feeds

Page 31: Using the Google AJAX APIs

31 (c)2008 Google

Building The Application

Building Blocks - Google Reader - www.google.com/reader

Tags and Sharing Feeds

Page 32: Using the Google AJAX APIs

32 (c)2008 Google

Building The Application

Building Blocks - Google Reader - www.google.com/reader

Tags and Sharing Feeds - Ads Verticals Examplehttp://www.google.com/reader/shared/user/X/label/Ads%20Verticals

Page 33: Using the Google AJAX APIs

33 (c)2008 Google

Building The Application

Building Blocks - Google Reader - www.google.com/reader

Tags and Sharing Feeds - Ads Verticals Feedhttp://www.google.com/reader/public/atom/user/X/label/Ads%20Verticals

Page 34: Using the Google AJAX APIs

34 (c)2008 Google

Building The Application

• CSE

– Custom Search Engine

– Better alternative than site restriction for large # of sites

– Enables search of all blogs

– All Google Blogs > 100 blogs

– Integrates directly with AJAX WebSearch

Building Blocks - Custom Search - www.google.com/cse

Page 35: Using the Google AJAX APIs

35 (c)2008 Google

Building The Application

Building Blocks - Custom Search - www.google.com/cse

Page 36: Using the Google AJAX APIs

36 (c)2008 Google

Building The Application

• Feed API

– Utilize Google Reader’s tag based feeds

– Mixed Format (XML and JSON) for tag cloud

– FeedControl for HTML generation

• Search API

– Blog or Web Search

– Customer Search Engine

– Why not Blog Search?

• Language API

– Detecting non-native languages

– Allow translation

Building Blocks - The Google AJAX APIs

Page 37: Using the Google AJAX APIs

37 (c)2008 Google

Building The Application

Getting Started - The HTML and CSS

<div id='container' class='container'> <div id='tabs' class='tabs'> <div id='categories' class='tabHeader tabActive'> Categories </div> <div id='blogs' class='tabHeader tabInactive'> Blogs </div> <div id='search' class='tabHeader tabInactive'> Search </div> </div>

<div id='tabView' class='tabView'> <div id='tabContentFrame' class='tabContentFrame'></div> </div> <div id='feedView' class='feedView'> <div id='feedContentView' class='feedContentView'></div> </div> <div id='searchView' class='searchView'></div> </div>

Page 38: Using the Google AJAX APIs

38 (c)2008 Google

Building The Application

Getting Started - The HTML and CSS

Tabs

TabView

DetailView

SearchControl

Page 39: Using the Google AJAX APIs

39 (c)2008 Google

Building The Application

• Bootstrapping the APIs and the application

Getting Started - The Google AJAX APIs

<script src="http://www.google.com/jsapi" type="text/javascript"></script>

<script type="text/javascript"> google.load('feeds', '1'); google.load('search', '1'); google.load('language', '1'); google.setOnLoadCallback(ogbInit);</script>

Page 40: Using the Google AJAX APIs

40 (c)2008 Google

Building The Application

• Initializing the application

Getting Started - The Google AJAX APIs

function ogbInit() { initData(); hookUI(); bootTagWeights();};

• Boot the top articles over all blogs using Google Reader Tag

– Reader tag ‘officialgoogleblogs-all’

– Utilize mixed format (XML and JSON) for source identifier

– Generate tag weights based on time and number of entries

Page 41: Using the Google AJAX APIs

41 (c)2008 Google

Building The Application

• The top entries for tag cloud generation

The Google AJAX Feed API

function bootTagWeights() { var url = urlFromLabel('officialgoogleblogs-all'); var feed = createFeed(url, google.feeds.Feed.MIXED_FORMAT); feed.load(tagWeightsLoaded);};

function createFeed(url, opt_format) { var format = (opt_format || google.feeds.Feed.JSON_FORMAT); var feed = new google.feeds.Feed(url); feed.setResultFormat(format); feed.setNumEntries(30); return feed;};

Page 42: Using the Google AJAX APIs

42 (c)2008 Google

Building The Application

• tagWeightsLoaded callback

The Google AJAX Feed API

function tagWeightsLoaded(result) {

... // Pull out source from top blog entries.. var ns = 'http://www.w3.org/2005/Atom'; var entries = result.feed.entries; for (var i=0; i <entries.length; i++) { var e = entries[i]; var sns=google.feeds.getElementsByTagNameNS(e.xmlNode,ns,'source'); var ins= google.feeds.getElementsByTagNameNS(sns[0], ns, 'id'); var id = ins[0].firstChild.nodeValue; ... } ...

};

Page 43: Using the Google AJAX APIs

43 (c)2008 Google

Building The Application

• tagWeightsLoaded callback - source

The Google AJAX Feed API

Page 44: Using the Google AJAX APIs

44 (c)2008 Google

Building The Application

• tagWeightsLoaded callback - source

The Google AJAX Feed API

Page 45: Using the Google AJAX APIs

45 (c)2008 Google

Building The Application

The Tag Cloud and Tag Selection

TagView

Page 46: Using the Google AJAX APIs

46 (c)2008 Google

Building The Application

• Loading and Displaying the Blog Feeds

The Google AJAX Feed API

function ogbShowFeed(url) { showStatus('Loading...'); var feed = createFeed(url); feed.load(function(result) { feedLoaded(result, url); });};

function feedLoaded(result, url) { var entries = result.feed.entries; for (var i=0; i <entries.length; i++) { feedControl.createHtml(entries[i]); if (entries[i].html) { feedView.appendChild(entries[i].html); } }};

Page 47: Using the Google AJAX APIs

47 (c)2008 Google

Building The Application

• The FeedControl and HTML generation

• Change JSON entry into standardized HTML nodes

• HTML attached to the JSON entry

• Applicable CSS classes

The Google AJAX Feed API - FeedControl

function feedLoaded(result, url) { var entries = result.feed.entries; for (var i=0; i <entries.length; i++) { feedControl.createHtml(entries[i]); if (entries[i].html) { feedView.appendChild(entries[i].html); } }};

Page 48: Using the Google AJAX APIs

48 (c)2008 Google

Building The Application

The Google AJAX Feed API - FeedControl

HTML

Page 49: Using the Google AJAX APIs

49 (c)2008 Google

Building The Application

• Override the default CSS class rules

• Base Structure

The Google AJAX Feed API - FeedControl

        <!-- One .gf-result per entry -->

        <div class="gf-result">          <!-- Hyperlinked Entry Title -->          <div class="gf-title">            <a class="gf-title"></a>          </div>          <!-- Author (Only if entry.author is present -->          <div class="gf-author"></div>          <!-- Published Date (Only if entry.publishedDate is present -->          <div class="gf-relativePublishedDate"></div>          <!-- Snippet entry.contentSnippet -->          <div class="gf-snippet"></div>        </div>

Page 50: Using the Google AJAX APIs

50 (c)2008 Google

Building The Application

• Override the default CSS class rules

The Google AJAX Feed API - FeedControl

#feedContentView .gs-title {text-decoration : none;}#feedContentView .gf-result, #feedContentView .gs-result {padding-bottom : 8px;width : 90%;overflow : hidden;}#feedContentView .gf-title a, #feedContentView .gs-title a {font-size : 16px;color : #DD8800;}#feedContentView .gf-snippet, #feedContentView .gs-snippet {color : #DDDDDD;padding-left : 5px;}

Page 51: Using the Google AJAX APIs

51 (c)2008 Google

Building The Application

The Blogs View

Blogs

Page 52: Using the Google AJAX APIs

52 (c)2008 Google

Building The Application

• Custom JSON Objects

– Maps all blogs to tags

– Build view based on all tags and corresponding blogs

– Tag selection and blog selection both generate detail view

The Blogs View

var blogs = [ { 'id': 'feed/http://feeds.feedburner.com/GoogleAdsenseChinaBlog', 'title': 'AdSense-\u4e2d\u6587', 'alternate': { 'href': 'http://adsense.googlechinablog.com/', 'type': 'text/html' }, tags : ['publishers'] }, .... ];

Page 53: Using the Google AJAX APIs

53 (c)2008 Google

Building The Application

The Google AJAX Search API

SearchControl

Page 54: Using the Google AJAX APIs

54 (c)2008 Google

Building The Application

• Search Control

– Place into DIV

• Searcher

– CSE

– searchComplete callback

The Google AJAX Search API

// Generate Search Form and SearchersearchForm = new google.search.SearchForm(false, searchView);searchForm.setOnSubmitCallback(null, searchSubmit);searcher = new google.search.WebSearch();searcher.setResultSetSize(google.search.Search.LARGE_RESULTSET);searcher.setSiteRestriction('000333901043914979043:yiaplyr6ps0');searcher.setSearchCompleteCallback(null, searchComplete);

Page 55: Using the Google AJAX APIs

55 (c)2008 Google

Building The Application

The Search Results View

Search Results

Page 56: Using the Google AJAX APIs

56 (c)2008 Google

Building The Application

The Google AJAX Language API - Translation

Original

Page 57: Using the Google AJAX APIs

57 (c)2008 Google

Building The Application

The Google AJAX Language API - Translation

Translated

Page 58: Using the Google AJAX APIs

58 (c)2008 Google

Building The Application

• Detecting Language

– Load feed and then detect language of each entry

– If not equal to CurrentLocale, add Translate icon

The Google AJAX Language API - Translation

{feedControl.createHtml(entries[i]);feedView.appendChild(entries[i].html)var cb = detectCallbackFunction(url, i); // Check for translation by detecting snippetgoogle.language.detect(entries[i].contentSnippet, cb);}

function detectCallback(result, url, i) { var entry = feedView.entries[i]; if (result.language != google.language.CurrentLocale) { log('Entry can be translated'); addTranslateIcon(entry); }};

Page 59: Using the Google AJAX APIs

59 (c)2008 Google

Building The Application

• Translating an entry

– Translate icon triggers translation of title and snippet

– Callback will replace contents appropriately

– Icon will toggle back and forth

The Google AJAX Language API - Translation

function processTranslation(index, elementId, result) { // Grab the correct item and replace.. var entry = feedView.childNodes[index]; var node; if (elementId == 'title') { node = entry.title(); } else { node = entry.snippet(); } node.innerHTML = result.translation;};

Page 60: Using the Google AJAX APIs

60 (c)2008 Google

Building The iGoogle Gadget

iGoogle Gadget

Page 61: Using the Google AJAX APIs

61 (c)2008 Google

Building The iGoogle Gadget

iGoogle Template

<?xml version="1.0" encoding="UTF-8" ?><Module><ModulePrefs title="All Google Blogs" directory_title="All Google Blogs" title_url="http://googleblog.blogspot.com" author=”Chris Schalk" author_affiliation="Google" author_location="Bay Area, CA" author_email="[email protected]" scrolling="false" category="tools" height="450" > </ModulePrefs><Content type="html"><![CDATA[ <<HTML inserted here>>]]></Content></Module>

Page 62: Using the Google AJAX APIs

62 (c)2008 Google

Reference Material

• General Documentation

– http://code.google.com/intl/ja/apis/ajaxsearch

– http://code.google.com/intl/ja/apis/ajaxfeeds

– http://code.google.com/intl/ja/apis/ajaxlanguage

• FeedControl

– http://code.google.com/intl/ja/apis/ajaxfeeds/documentation/reference.html#FeedControl

• Development Tools

– Firebug

• http://getfirebug.com

– Firebug Tutorial

• http://code.google.com/support/bin/answer.py?answer=94630&topic=11530

Page 63: Using the Google AJAX APIs

Learn more

http://code.google.com/

Contact info:

http://chrisschalk.com

Slides will be posted onslideshare.net!

Page 64: Using the Google AJAX APIs