Tải bản đầy đủ (.pdf) (329 trang)

Wrox professional development with web APIs google EBay amazon com mappoint fedex apr 2005 ISBN 0764584456 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.75 MB, 329 trang )


Professional Web APIs: Google®, eBay®,
Amazon.com®, MapPoint®, FedEx®
Denise Gosnell



Professional Web APIs: Google®, eBay®,
Amazon.com®, MapPoint®, FedEx®



Professional Web APIs: Google®, eBay®,
Amazon.com®, MapPoint®, FedEx®
Denise Gosnell


Professional Web APIs: Google®, eBay®, Amazon.com®,
MapPoint®, FedEx®
Copyright © 2005 by Denise Gosnell. All rights reserved.
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate percopy fee to the Copyright Clearance Center, 222
Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis,
IN 46256, (317) 572-3447, fax (317) 572-4355, e-mail: or online at http://www. wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR
MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR
COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL
WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT


THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A
COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOT
THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN
ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A
POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR
THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY
PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED
BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department
within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, Programmer to Programmer, and
related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates. Google is a registered trademark of Google, Inc. eBay is a registered trademark of eBay, Inc.
Amazon.com is a registered trademark of Amazon.com. MapPoint is a registered trademark of Microsoft
Corporation. FedEx is a registered trademark of Federal Express Corporation. All other trademarks are
the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or
vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic books.
Library of Congress Cataloging in Publication Data is Available from the Publisher.
ISBN-13: 978-0-7645-8445-9
ISBN-10: 0-7645-8445-6
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1


About the Author
Denise Gosnell is a software attorney with Woodard, Emhardt, Moriarty, McNett & Henry LLP
(www.uspatent.com), a worldwide intellectualproperty law firm based in Indianapolis, Indiana. Denise
has a unique background in both technology and law, and presently uses her deep technical and legal

expertise to counsel hightech clients on intellectual property and technical matters.
Denise has over ten years of experience creating software applications, ranging from standalone and
clientserver to enterprisewide applications. Denise has worked for leading software companies, such as
Microsoft and EDS, and has earned a worldwide reputation for her technology expertise. She received a
Bachelor of Arts degree in Computer Science – Business (summa cum laude) from Anderson University,
and a Doctor of Jurisprudence degree from Indiana University School of Law in Indianapolis.
Denise has coauthored six other software development books to date: Beginning Access 2003 VBA (Wiley
Publishing, Inc.), Visual Basic .NET and SQL Server 2000: Building An Effective Data Layer (Wrox Press),
Beginning Visual Basic.NET Databases (Wrox Press), Professional .NET Framework (Wrox Press), Professional SQL
Server 2000 (Wrox Press), and MSDE Bible (IDG Books). Denise was a featured technology speaker at the
Microsoft European Professional Developer’s Conference in December 2001 and has on numerous occasions
assisted Microsoft’s Training and Certification group in creating new exams for their MCSD and MCSE certifications. She herself holds the MCSD certification.
Denise can be reached at or



Credits
Vice President and Executive Group Publisher:

Senior Production Editor:

Richard Swadley

Angela Smith

Vice President and Publisher:

Technical Editor:

Joseph B. Wikert


Daniel Solin

Executive Editor:

Text Design & Composition:

Chris Webb

Wiley Composition Services

Editorial Manager:
Mary Beth Wakefield

Development Editor:
Sharon Nash



Acknowledgments
Until I became an author, I had no idea that so many people other than the author have to spend countless hours to make a book a reality. It would be impossible for me to thank everyone who made this
book possible, but I would like to acknowledge the fine staff at Wiley for their dedication to this project
and all he other projects that they work on each day.
I would like to offer a special thanks to Chris Webb, my Executive Editor, for all of his input initially on
the direction this book should take and for his continued assistance throughout the editorial process. I
also owe a special thanks to Sharon Nash, my Development Editor, for her editorial input that added the
finishing touches to my work. A special thanks is also due to Daniel Solin for his technical review of the
book and his great feedback.
I would like to thank my husband, Jake, and my friends and family, for their continued support of my
authoring efforts. I spend many moments of my spare time working on new books, and without your

patience and understanding, this would not be possible.
Thanks to Carl and Leona Stapel of Oshkosh, Wisconsin, for showing me and my husband the world
through our many travels with you. I have gained a much broader perspective in our travels, and that
has made me a better person and author.
And last, but not least, I thank God for giving me the talent, energy, and positive attitude that allow me
to pursue my dreams.



Contents
Acknowledgments
Introduction

ix
xvii

Chapter 1: Anatomy of a Web API

1

Web APIs versus Web Services
Web APIs as XML Web Services

1
2

What Is XML?
Invoking an XML Web Service

Summary


Chapter 2: Using the Google API
Google 101
cache:
daterange:
filetype:
inanchor:
info:
intext:
intitle:
inurl:
link:
phonebook:
related:
site:

Introduction to the Google API
Signing Up and Obtaining a Key

Anatomy of a Google API Query
Query Syntax
Executing a Query
Looping through Results

Five Creative Ways to Use the Google API
#1 — Build a Google Search Feature
#2 — Return Random Pages
#3 — Save the Results of a Google Search to a File
#4 — Use Google to Check Spelling
#5 — Use the Google Cache to Retrieve a Web Site That Is No Longer Available


2
3

14

15
15
16
17
17
18
18
18
18
18
19
19
19
19

19
19

23
23
25
31

33

33
36
37
40
42


Contents
Other Ways to Use the Google API
Third-Party Google Extensions
Summary

45
46
48

Chapter 3: Using the MapPoint API

49

MapPoint 101
Introduction to the MapPoint API

50
51

Signing Up for an Evaluation Account
The MapPoint Software Developer’s Kit (SDK)

Anatomy of a MapPoint API Query


52
58

59

Available Services
Using the Test Environment versus Production
Executing a MapPoint Query

59
63
63

Five Creative Ways to Use the MapPoint API

71

#1 — Obtain Driving Directions
#2 — Retrieve a Map
#3 — Perform a Geocode Lookup
#4 — Find Nearby Places
#5 — Obtain Information on Points of Interests

72
75
77
80
82


Other Ways to Use the MapPoint API
Third-Party MapPoint Extensions
Summary

84
85
85

Chapter 4: Using the Amazon.com APIs

87

Amazon 101
Introduction to the Amazon APIs

88
90

Supported Features
Signing Up for a Subscription ID

90
91

Anatomy of Amazon API Queries

96

Amazon.com E-Commerce Service API Query Syntax
Help Operation

Transaction Operation
Alexa Web Information Service API Query Syntax
Simple Queue Service API Query Syntax
Executing a Query Using HTTP-GET (REST)
Executing a Query Using SOAP
Looping Through Results

Five Creative Ways to Use the Amazon APIs
#1 — Retrieve Feedback about a Seller with ECS
#2 — Retrieve Product Pricing with ECS

xii

97
102
102
102
103
104
106
109

110
110
110


Contents
#3 — Look Up a Friend or Family Member’s Wish List with ECS
#4 — Create an Amazon.com Shopping Cart with ECS

#5 — Retrieve URL Information with Alexa Web Information Service

Other Ways to Use the Amazon APIs
Third-Party Amazon Extensions
Summary

110
111
112

112
113
115

Chapter 5: Using the eBay API

117

eBay 101
Introduction to the eBay API

118
118

Supported Features
Licensing Options
Joining the Developer’s Program and Establishing an Account
The eBay API Documentation
The eBay Software Developer’s Kit (SDK)


Anatomy of an eBay API Query
Query Syntax
Executing a Query Using HTTP-POST
Executing a Query Using SOAP

Five Creative Ways to Use the eBay API
#1 — List an Item for Sale
#2 — Retrieve a List of Categories
#3 — Retrieve List of Pending Auctions for Seller
#4 — Retrieve Winning Bidders of Dutch Auction
#5 — Retrieve Feedback about a Seller

119
119
119
124
124

125
125
127
130

132
133
137
138
141
142


Other Ways to Use the eBay API
Third-Party eBay Extensions
Summary

144
145
146

Chapter 6: Using the PayPal API

147

PayPal 101
Introduction to the PayPal API

148
148

Supported Features
Getting Set Up to Use the PayPal API

Anatomy of a PayPal API Query
Query Syntax
Executing a Query

Other Ways to Use the PayPal API
Third-Party PayPal Extensions
Summary

149

149

158
158
160

162
162
162

xiii


Contents
Chapter 7: Other Web APIs
Faxing APIs
Setting Up a Free Developer Account
Sending a Test Fax

The UPS API
Setting Up a UPS Developer Account
Submitting a Request to the UPS API

The FedEx APIs
Setting Up a FedEx Developer Account
Submitting Transactions Using FedEx Ship Manager Direct

Bloglines Web API
Locating Additional Web APIs
Summary


Chapter 8: Calling Web APIs from Mobile Devices

163
163
164
165

168
168
170

172
173
175

176
178
180

181

What Devices Support XML Web APIs?

181

Windows Pocket PCs and Smartphones
Palm and Other Devices

182

183

Calling Web APIs from Pocket PC Applications
Example 1 — Call MapPoint API Using SOAP Protocol to Retrieve Driving Directions
Example 2 — Call Amazon.com API Using HTTP/GET (REST) Protocol

Summary

Chapter 9: Calling Web APIs from Microsoft Office
Calling Web APIs from VBA Code
Calling Web APIs Using VBA with HTTP/POST and HTTP/GET (REST)
Calling Web APIs Using SOAP Protocol

Calling a Web API from Microsoft Office Using .NET
Installing the Necessary Tools
Example — Calling Amazon.com Web Service from Word Using
Visual Basic .NET and SOAP

Summary

Chapter 10: Creating Your Own Web API
Designing the API
What Features Should the API Offer?
Which Protocols Should the API Support?
Should the Features Be Free or for a Fee?

xiv

184
184

189

192

193
193
194
196

202
203
205

211

213
213
213
214
215


Contents
Creating a Web API
Building an API Using Visual Studio .NET
Calling the Web API from a Client Application
Creating a Web API That Uses Other Programs or Services

Summary


Chapter 11: Case Study 1 — Customer Relations
Management Application
Introduction to the Customer Relations Management (CRM) Application
Building the Project
Build the Database
Build the User Interface
Build the Modules

Touring the Completed Application
Summary

Chapter 12: Case Study 2 — Executive Dashboard Application
Introduction to the Executive Dashboard Application
Building the User Interface
Creating the New Project
Adding References to the Web APIs
Adding Controls to the Form

215
216
222
224

224

225
225
228
228
230

237

260
263

265
265
267
267
268
270

Building the Code Modules
Touring the Completed Application
Summary

272
276
279

Index

281

xv



Introduction
Web APIs are a set of application programming interfaces that can be called over standard Internet protocols. Web APIs and Web services are finally getting real attention in the mainstream. Various types of Web

APIs are now available from leading technology companies such as Google, Amazon, eBay, Microsoft, and
others. Federal Express, UPS, and many other leading companies have recently released or are working
on Web APIs as well. Most of these companies offer a free account for limited use of their Web APIs, but
some charge a fee for certain levels of usage.
If you like the idea of generating applications that capitalize on the services of some of these wellknown
companies, or if you just want to learn from what these leading companies are doing to aid you in implementing your own Web APIs, then this is the book for you.

Who This Book Is For
The ideal reader has had prior experience with Microsoft .NET development, such as WinForms and
WebForms applications because most or all code examples will be written with .NET. However, the book
also provides general explanations that will be useful for people who are familiar with other languages.
Thus, prior .NET development experience is not required, but people with prior .NET development
experience will find the code examples more familiar and easier to follow.

What This Book Covers
This book provides a handson guide to using some of the most popular Web APIs in software applications.
It provides the nutsandbolts details on how several APIs work, and then offers numerous examples of how
to use the APIs in real world situations.
While reading this book, you will learn:


Basic concepts of Web APIs



How Web APIs can be used for professional application development



How to call Web APIs using SOAP over HTTP




How to call Web APIs using HTTPGET (REST)



How to call Web APIs using HTTPPOST



How to use the Google API



How to use the MapPoint API


Chapter #
Introduction


How to use the Amazon API



How to use the eBay API and SDK




How to use the PayPal API



How to locate additional APIs



Some thirdparty extensions of existing APIs



How to create your own API



How to call Web APIs from Microsoft Office applications



How to call Web APIs from mobile devices



How to use multiple APIs together in realworld case studies

How This Book Is Structured
When designing the direction for this book, one issue I struggled with was whether to spend multiple
chapters on a single Web API or whether to cover each API solely in its own chapter. I came up with a
solution that provides a very good balance.

The first part of the book is a cookbook of sorts that illustrates how to use various Web APIs. Chapter 1
introduces some general Web API concepts. Chapter 2 covers Google, Chapter 3 covers Microsoft MapPoint,
Chapter 4 covers Amazon.com, Chapter 5 covers eBay, and Chapter 6 covers PayPal. Chapter 7 includes
some additional APIs, including FedEx, UPS, InterFax, and Bloglines. Each APIspecific chapter is structured
in the same fashion and provides the following:

1.
2.
3.
4.
5.
6.

An introduction to the general features that vendor offers (not specific to the Web API)
Details about how the API works and how to obtain an account to work with it
A stepbystep example to illustrate using the Web API (from .NET and in general)
Five creative examples to illustrate how to further use the API
Additional ideas on how the API can be used to give you other options to explore on your own
Examples to show how other people have used the API

The latter part of the book includes nonAPIspecific chapters to really illustrate the creative ways you
can work with Web APIs. Chapter 8 discusses calling the Web APIs from Mobile Devices. Chapter 9 discusses how to call the Web APIs from Microsoft Office. Chapter 10 then explores how to create Web APIs
from scratch and how to capitalize on that offering. Chapters 11 and 12 are case studies that combine
multiple Web APIs in an integrated solution.

xviii


Introduction
For example, in Chapter 11, you will build a Customer Relations Management application that allows

users to track information about customers and potential customers, including such information as
name, address and phone number. The Google API and MapPoint API are used to further extend the
capabilities of the application. For example, the application uses the Google API to retrieve and display
the first five sites that mention the particular contact when you open a contact record. An example of
this is shown in Figure 11-18.

Figure 11-18

The idea behind this Google box is to allow you to see current information about your contacts or their
companies before giving them a call. The MapPoint API is then used to enable you to retrieve a map or
driving directions to the contact’s specified address, as shown in Figures 11-19 and 11-21.

xix


Introduction

Figure 11-19

Figure 11-21

xx


Introduction
In Chapter 12, you build an Executive Dashboard Application, which is a browserbased application that
combines results from multiple APIs. The application can be used to retrieve product information and
reviews from Amazon.com, Google, and eBay for display on a single Web page.
After entering a search criteria and selecting a search option, you see the Amazon.com page first that
most closely matched the criteria. An example of this is illustrated in Figure 12-11.


Figure 12-11

Upon scrolling down in the browser, you also see a product review page from Epinions.com that most
closely matches the criteria. The page was retrieved by running a Google search that was limited to the
Epinions.com site. An example of this is shown in Figure 12-12.

xxi


Introduction

Figure 12-12

Finally, as shown in Figure 12-13, when you scroll down to the bottom of the page, you see listings from
eBay that contain the search criteria.
The chapters are structured with standalone examples that do not require you to follow the chapters in
order. This structure enables you to go straight to a chapter that interests you or to skip around among
chapters as desired. Certainly, some chapters will not make as much sense unless you have read the
prior chapters or are already familiar with the topics covered therein.

xxii


×