Google’s Web Service January 4, 2004 Shuying Wang.

21
Google’s Web Service January 4, 2004 Shuying Wang

Transcript of Google’s Web Service January 4, 2004 Shuying Wang.

Page 1: Google’s Web Service January 4, 2004 Shuying Wang.

Google’s Web Service

January 4, 2004

Shuying Wang

Page 2: Google’s Web Service January 4, 2004 Shuying Wang.

Overview

• An introduction to Web Service– SOAP & WSDL

• Google’s Web Service Architecture

• Google Web API

• Google Web API application

Page 3: Google’s Web Service January 4, 2004 Shuying Wang.

Web Evolution

XMLXML

ProgrammableProgrammable

WebWeb

Static WebStatic Web

DHTML JSP ASP…

DHTML JSP ASP…

Dynamic WebDynamic Web

HTMLHTML

Technology

Technology

Innovation

Innovation

Web Pages

Web Pages Alternate Web Pages

Alternate Web Pages

Browse Browse the Webthe Web

Program Program the Webthe Web

Web Services

Web Services

Page 4: Google’s Web Service January 4, 2004 Shuying Wang.

What Is A Web Service?

This is the official W3C take on a Web service definition: “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. ”

Page 5: Google’s Web Service January 4, 2004 Shuying Wang.

Architecture of Web Service

Page 6: Google’s Web Service January 4, 2004 Shuying Wang.

Simple Object Access Protocol – SOAP 1.2

• Generic XML-based RPC protocol• Initial specification only covers HTTP-

binding• Use of XML Schema• Multiple protocol bindings available

today(SMTP, FTP, JMS, etc.)• RPC-style and document-style

communication

Page 7: Google’s Web Service January 4, 2004 Shuying Wang.

Example SOAP Message Request

• A standard XML-based format to describe a SOAP request for a Web Service

• Provides all the information required by the Web Service provider to process the request

• General format of a SOAP request:

HTTP Header SOAP Action

<SOAP-ENV:Envelope> <SOAP-ENV:Header> <!-- Soap Header is optional --> </SOAP-ENV:Header> <SOAP-ENV:Body> <!-- Serialized method invocation data --> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 8: Google’s Web Service January 4, 2004 Shuying Wang.

Example SOAP Message Reponse

• A standard XML-based format to describe the Response generated by a Web Service

• Contains information that is to be passed back to the client

• General format of a SOAP response:

HTTP Header

<SOAP-ENV:Envelope> <SOAP-ENV:Body> <!-- Serialized Response Data --> </SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 9: Google’s Web Service January 4, 2004 Shuying Wang.

Web Service Definition Language-WSDL(1)

• From the spec: “XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information.”

• In another word, WSDL is XML Based Language for describing web services and how to access them

Page 10: Google’s Web Service January 4, 2004 Shuying Wang.

Web Service Definition Language-WSDL(2)

WSDL describes four pieces of critical data:• Interface information describing all publicly

available functions• Data type declarations for all message

requests and responses• Binding information about the transport

protocol• Address information for locating the service

Page 11: Google’s Web Service January 4, 2004 Shuying Wang.

Web Service at Google

• In 2002 Google and Amazon introduced Web services APIs

• SOAP API for accessing Google– Requires registration for a developer’s license

key– Limit of 1000 queries per day– According to license terms only way to access

Google programmatically

Page 12: Google’s Web Service January 4, 2004 Shuying Wang.

Google Web Service Architecture

                                                                       

Page 13: Google’s Web Service January 4, 2004 Shuying Wang.

Google API Language Support

Google.com

Google API

Google API

Google API

Google APIGoogle API

.NET

JavaPerl

c

PHP

Web Service client

Web Service client

Web Service client

Web Service client

Web Service client

SOAP request

SOAP request

SOAP requestSOAP

response

SOAP response

SOAP response

Page 14: Google’s Web Service January 4, 2004 Shuying Wang.

The Google Web APIs Developer’s Kit

• http://www.google.com/apis/download.html– A cross-platform WSDL file– A Java wrapper library– A sample .NET application– Documentation, including JavaDoc and SOAP

XML samples

Page 15: Google’s Web Service January 4, 2004 Shuying Wang.

Google Web API

• Beta version supports 3 types of queries:– doSearch– doGetCachedPage – doSpellingSuggestion.

Page 16: Google’s Web Service January 4, 2004 Shuying Wang.

Understanding the Google API query

• The command in a typical Perl-based Google API applicaton that sends a query to Google looks like:

$results = $google_search->

doGoogleSearch(key, query, start, maxResults, filter, restrict, safeSearch, lr, ie, oe);

Page 17: Google’s Web Service January 4, 2004 Shuying Wang.

A sample

$results = $google_search-> doGoogleSearch(“12BucK13mY5hoE/34KN0cK@ttH3Do0R”, “+music +mp3”,100, 10, “true”, “”, “true”, “”, “utf8”, “utf8”);

Page 18: Google’s Web Service January 4, 2004 Shuying Wang.

Google API response

• Can Do– Site– Daterange– Intitie– Inurl– Allintext– Allinlinks– Filetype– Info– Link– Related– Cache

• Can’t Do– phonebook– rphonebook– bphonebook– stocks

Page 19: Google’s Web Service January 4, 2004 Shuying Wang.

Programming the Google Web API with Java

import com.google.soap.search.*;import java.io.*;public class Googly { private static String googleKey = "insert key here"; public static void main(String[] args) { GoogleSearch s = new GoogleSearch( ); // Create a new GoogleSearch object try { s.setKey(googleKey); s.setQueryString(args[0]); // Google query from the command-line s.setMaxResults(10);

GoogleSearchResult r = s.doSearch( ); // Query Google GoogleSearchResultElement[] re = r.getResultElements( ); // Gather the results for ( int i = 0; i < re.length; i++ ) { // Output System.out.println(re[i].getTitle( )); System.out.println(re[i].getURL( )); System.out.println(re[i].getSnippet( ) + "\n"); } } catch (GoogleSearchFault f) { System.out.println("GoogleSearchFault: " + f.toString( )); } } }

Page 20: Google’s Web Service January 4, 2004 Shuying Wang.

Google API application

Page 21: Google’s Web Service January 4, 2004 Shuying Wang.

Resources

• http://www.w3c.org/• http://www.google.com/apis/• “Guided Google: A Meta Search Engine

and its Implementation using the Google Distributed Web Services” Ding Choon Hoong & Rajkumar Buyya

• “Google HACKS” Tara Calishain & Rael Dornfest