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

How to Do Everything with Web 2.0 Mashups phần 1 pptx

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 (1.67 MB, 33 trang )

Simpo PDF Merge and Split Unregistered Version -
How to Do Everything with
Web 2.0 Mashups
New York Chicago San Francisco Lisbon
London Madrid Mexico City Milan New Delhi
San Juan Seoul Singapore Sydney Toronto
Jesse Feiler
Simpo PDF Merge and Split Unregistered Version -
Copyright © 2008 by The McGraw-Hill Companies. All rights reserved. Manufactured in the United States of America. Except as permitted
under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or
stored in a database or retrieval system, without the prior written permission of the publisher.
0-07-159568-6
The material in this eBook also appears in the print version of this title: 0-07-149627-0.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name,
we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the
trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training
programs. For more information, please contact George Hoare, Special Sales, at or (212) 904-4069.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use
of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the
work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit,
distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for
your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if
you fail to comply with these terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO
THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK,
INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND
EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant
or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free.


Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the
work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work.
Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive,
consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the
possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in
contract, tort or otherwise.
DOI: 10.1036/0071496270
Simpo PDF Merge and Split Unregistered Version -
We hope you enjoy this
McGraw-Hill eBook! If
you’d like more information about this book,
its author, or related books and websites,
please click here.
Professional
Want to learn more?
Simpo PDF Merge and Split Unregistered Version -
For Anne Kaufman
Simpo PDF Merge and Split Unregistered Version -
About the Authors
Jesse Feiler has written a number of books about FileMaker, Mac OS X, the Web, and new
technologies; his books have been translated into Japanese, Chinese, Polish, German, Spanish,
French, and other languages. His most recent book is Special Edition Using FileMaker 9. As
director of North Country Consulting, he has designed and implemented a variety of solutions
for small businesses and nonprofits in fields such as production, marketing, the arts, printing
and publishing, food service, and construction. He has taught and consulted widely on nonprofit
governance, and he is the founder of ChamplainArts.com—a listing of cultural events in 2 states,
2 countries, and 2 languages.
About the Technical Editor
Jim Bumgardner is a senior technical guru at Yahoo! Music, a teacher at Pasadena’s Art Center
College of Design, and the creative mind behind CoverPop.com and CrazyDad.com. An expert

in graphics and music software, Jim makes mashups, software toys, and experimental user
interfaces using Flash, JavaScript, PHP, and other tools.
Simpo PDF Merge and Split Unregistered Version -
v
Contents at a Glance
PART I Introducing Mashups
1 Welcome to the World of Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Understanding the Mashup World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
PART II Learn Mashup Technologies
3 Know the Web 2.0 Mashup Rules and Design Principles . . . . . . . . . . . . . 25
4 Use XML to Structure Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5 Use JavaScript to Script the Mashup Page . . . . . . . . . . . . . . . . . . . . . . . . 47
6 Use PHP to Perform Server-Side Scripting . . . . . . . . . . . . . . . . . . . . . . . . 61
7 Use MySQL with PHP to Retrieve Mashup Data . . . . . . . . . . . . . . . . . . . 79
8 Use RSS and Atom to Receive Data Automatically . . . . . . . . . . . . . . . . . 97
9 Use XMLHttpRequest, XML-RPC, REST, and JSON
to Retrieve Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
10 Use XHTML to Structure the Mashup Pages . . . . . . . . . . . . . . . . . . . . . . 127
PART III
Build Your Own Mashups
11 Implement a Basic Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
12 Use the Google Maps API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
13 Build Mashups with the Google Maps API . . . . . . . . . . . . . . . . . . . . . . . . 179
14 Use the Amazon Web Services and Google Search APIs . . . . . . . . . . . . . 205
15 Build a Mashup to Search Amazon and Google at the Same Time . . . . . . 225
16 Use the Flickr API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
17 Build a Mashup to Search Flickr and Google at the Same Time . . . . . . . . 255
18 Use the eBay API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
19 Map the Locations of eBay Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Simpo PDF Merge and Split Unregistered Version -
This page intentionally left blank
Simpo PDF Merge and Split Unregistered Version -
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
PART I Introducing Mashups
CHAPTER 1 Welcome to the World of Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Sell Things with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Provide Information with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Create Art with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CHAPTER 2 Understanding the Mashup World . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Describe a Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Use Multisource Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Use Presentation Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Build Your Own Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . 18
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Regroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Design the User Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Make Money with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Achieve Goals with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Improve Productivity with Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Know How to Use Mashup Data Legally . . . . . . . . . . . . . . . . . . . . . . . . 21
PART II Learn Mashup Technologies
CHAPTER 3 Know the Web 2.0 Mashup Rules and Design Principles . . . . . . . . 25
Manage Multiple Technologies for Mashups . . . . . . . . . . . . . . . . . . . . . 26
Separate Data from Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Contents
vii
For more information about this title, click here
Simpo PDF Merge and Split Unregistered Version -
viii How to Do Everything with Web 2.0 Mashups
Use Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Server-Side Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Browser-Side Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Access Data with APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Minimize Full-Page Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Make Your Mashup Visible to Search Engines . . . . . . . . . . . . . . . . . . . . 32
Use Object-Oriented Programming Techniques . . . . . . . . . . . . . . . . . . . 33
Adopt Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
CHAPTER 4 Use XML to Structure Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Understand XML Structure and Purpose . . . . . . . . . . . . . . . . . . . . . . . . 36
Learn Basic XML Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Create and Use XML Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Use Attributes to Identify Data Characteristics . . . . . . . . . . . . . . . . . . . . 44
Avoid Confusion by Using Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . 45
CHAPTER 5 Use JavaScript to Script the Mashup Page . . . . . . . . . . . . . . . . . . . . 47
Understand JavaScript Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Place JavaScript Scripts in Script Elements . . . . . . . . . . . . . . . . . 49
Use Scripts from an External Source with the src Attribute . . . . . 49
Scripts Are Interpreted as They Are Encountered on the
HTML Page Unless They Are in the Head Element . . . . . . . . 50
You Can Use Semicolons to End Statements . . . . . . . . . . . . . . . . 50
Continue Quoted Text Strings with \ and Concatenation (+) . . . . 50
Use Spaces and Comments for Readability . . . . . . . . . . . . . . . . . 51
JavaScript Is Case-Sensitive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Use Local and Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Create and Use Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Use JavaScript Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Work with Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Handle Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Handle JavaScript Environmental Problems . . . . . . . . . . . . . . . . . . . . . . 57
CHAPTER 6 Use PHP to Perform Server-Side Scripting . . . . . . . . . . . . . . . . . . . . 61
Understand PHP Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Use PHP Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Use Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Terminate PHP Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Start a PHP Script by Submitting an HTML Form . . . . . . . . . . . . . . . . . 65
Use PHP Variables and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Use PHP Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Differentiating Between Single and Double Quotes . . . . . . . . . . 69
Using Heredoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Building Concatenated Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Control PHP Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Simpo PDF Merge and Split Unregistered Version -
Contents ix
Build a Web Page with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The HTML Source Code to Be Built . . . . . . . . . . . . . . . . . . . . . . 72
The PHP Code to Build the HTML Source Code . . . . . . . . . . . . 73
Structure Multiple PHP Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
CHAPTER 7 Use MySQL with PHP to Retrieve Mashup Data . . . . . . . . . . . . . . . . 79
Understand SQL and Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Create SQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Use the FEC Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Use MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Use PHP to Get to an SQL Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Connect to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

Create and Process the Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Fetch the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Disconnect from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Create and Load a Test Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Create a Test Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Load the Test Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Delete Data from the Test Database . . . . . . . . . . . . . . . . . . . . . . . 95
CHAPTER 8 Use RSS and Atom to Receive Data Automatically . . . . . . . . . . . . . . 97
Understand Syndication, RSS, and Atom . . . . . . . . . . . . . . . . . . . . . . . . 99
RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Categorize and Label a Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Parse a Feed with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Inside the Feed’s XML Document . . . . . . . . . . . . . . . . . . . . . . . . 104
Implement the Form to Launch the Script . . . . . . . . . . . . . . . . . . 110
Implement the PHP Script to Parse the Feed . . . . . . . . . . . . . . . . 111
Create a Search Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
CHAPTER 9 Use XMLHttpRequest, XML-RPC, REST, and JSON
to Retrieve Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Understand Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Deal with Cross-Domain Scripting Issues . . . . . . . . . . . . . . . . . . . . . . . 115
Use XMLHttpRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Constructing and Sending an XMLHttpRequest . . . . . . . . . . . . . 117
Handling an XMLHttpRequest Response . . . . . . . . . . . . . . . . . . 118
Putting It Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Implement an XML-RPC Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Implement a REST Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Implement a JSON Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
CHAPTER 10 Use XHTML to Structure the Mashup Pages . . . . . . . . . . . . . . . . . . . 127
Understand the Need for XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

HTML’s Ease of Use Is a Two-Edged Sword . . . . . . . . . . . . . . . . 129
Simpo PDF Merge and Split Unregistered Version -
x How to Do Everything with Web 2.0 Mashups
The XHTML Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Why This Matters for Mashups . . . . . . . . . . . . . . . . . . . . . . . . . . 130
What Makes XHTML Code Tricky for Mashup Results Pages? . . . 131
The Sample XHTML Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Use XHTML Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The XML Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The Document Type Declaration (DTD) . . . . . . . . . . . . . . . . . . . 133
The HTML Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Use XHTML Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
XHTML Documents Can (and Should) Contain Comments . . . . 134
XHTML Element Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
XHTML Attribute Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Documents Should Be Well-Formed and Valid . . . . . . . . . . . . . . 136
Validate XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
PART III Build Your Own Mashups
CHAPTER 11 Implement a Basic Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The Population Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The Labor Force Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Load Labor Force Data into MySQL . . . . . . . . . . . . . . . . . . . . . . 152
Load Population Data into MySQL . . . . . . . . . . . . . . . . . . . . . . . 155
Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Regroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Design the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
CHAPTER 12 Use the Google Maps API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Get Access to the Google Maps API . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Create the Basic Mapping Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Create a Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Identify a Location with a GLatLng . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Use a Geocoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Create a Marker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Add Text to a Marker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Putting It Together in the Callback Function . . . . . . . . . . . . . . . . . . . . . 173
Wrap It Up in PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
CHAPTER 13 Build Mashups with the Google Maps API . . . . . . . . . . . . . . . . . . . . 179
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Simpo PDF Merge and Split Unregistered Version -
Contents xi
Create a Campaign Contributions Mashups . . . . . . . . . . . . . . . . . . . . . . 192
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . 192
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Regroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Design the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
CHAPTER 14 Use the Amazon Web Services and Google Search APIs . . . . . . . . . 205
Get Access to the Amazon API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Setting Up an Amazon Account . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Setting Up an Amazon Associate Account . . . . . . . . . . . . . . . . . . 207
Setting Up an Amazon Web Services Account . . . . . . . . . . . . . . . 209

Search Amazon for an Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Required Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
General Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Specific Parameters for ItemSearch . . . . . . . . . . . . . . . . . . . . . . . 214
Put It Together: An Amazon Search REST Query . . . . . . . . . . . . 214
Build an Amazon Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Build an Amazon Shopping Cart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Use the Google Search API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
CHAPTER 15 Build a Mashup to Search Amazon and Google
at the Same Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Design the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
The Basic Mashup Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Code the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Add Debugging and Error-Checking Code . . . . . . . . . . . . . . . . . . . . . . . 236
Debugging Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Debugging the XML from Amazon . . . . . . . . . . . . . . . . . . . . . . . 237
Checking the Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Testing Error-Checking Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
CHAPTER 16 Use the Flickr API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Get Access to the Flickr API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Getting a Key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Exploring the API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Search for Photos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Use API Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Display a Photo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250

Simpo PDF Merge and Split Unregistered Version -
xii How to Do Everything with Web 2.0 Mashups
CHAPTER 17 Build a Mashup to Search Flickr and Google at the Same Time . . . 255
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Design the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
CHAPTER 18 Use the eBay API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Get Access to the eBay API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Use the API Test Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Generating the Token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Making the API Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Use the REST Interface for GetSearchResults . . . . . . . . . . . . . . . . . . . . 271
Define Your Token and User ID . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Set Up Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Create the Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Execute the Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Use the SOAP Interface for GetSearchResults . . . . . . . . . . . . . . . . . . . . 274
Define Your Token and User ID . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Set Up Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Create the Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Execute the Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Parse the XML Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
CHAPTER 19 Map the Locations of eBay Items . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Decide on Your Mashup’s Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Identify the Data and the Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Get Access to the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Design the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

Implement the Mashup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Implement the Page Top Include . . . . . . . . . . . . . . . . . . . . . . . . . 282
Implement the PHP Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Implement the Starting Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
What’s Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Simpo PDF Merge and Split Unregistered Version -
xiii
Roger Stewart and Carly Stapleton at McGraw-Hill worked tirelessly to help move this book along.
Carole McClendon, at Waterside Productions as always contributed her skills and expertise.
Jim Bumgardner’s technical edits were invaluable; you will notice several code snippets and
specific suggestions from Jim that I’m happy to be able to pass along.
Acknowledgments
xiiixiiixiii
Simpo PDF Merge and Split Unregistered Version -
This page intentionally left blank
Simpo PDF Merge and Split Unregistered Version -
xv
Introduction
Few developments in the world of computers have been embraced as quickly as mashups. The
most common mashups remain those that build on the various mapping APIs, but dynamic
combinations of data from multiple sources or in multiple formats (the basic definition of a
mashup) are all over the Web. Part I of this book provides an introduction to the world
of mashups.
Mashups require you to know a little bit about a number of Web technologies, and that
is what you will find in Part II. Long books have been written about each of the technologies
described in the chapters of Part II, but what you will find here is guidance about the specific
parts of those technologies you are likely to use.
In Part III, the technologies are put together to build mashups. The first chapter of this part
of the book introduces the basic steps common to building all mashups in the book. Then, you

will find pairs of chapters: the first introduces a specific API (eBay, Google Maps, Flickr, and so
forth), and the second builds on the technologies of Part II and the specific API to create
a mashup.
The code described in most chapters is available on the author’s Web site (www
.northcountryconsulting.com—the Downloads link is at the right of the page, just beneath the
bio), as well as on the McGraw-Hill Web site (www.mhprofessional.com, or more precisely,
The downloadable code is in
self-extracting ZIP archives and is organized by chapter. Because the examples are built from
chapter to chapter, make certain that you are using the right chapter’s code: the mashup from one
chapter will have only a fraction of the code as the same mashup in a later chapter.
Note that most of the mashup code requires you to register to use the API involved. (This is
described in the book.) The code that you download will not run until you replace placeholders
such as myAccountName with your actual account name.
Simpo PDF Merge and Split Unregistered Version -
This page intentionally left blank
Simpo PDF Merge and Split Unregistered Version -
Part I
Introducing Mashups
Simpo PDF Merge and Split Unregistered Version -
This page intentionally left blank
Simpo PDF Merge and Split Unregistered Version -
Chapter 1
Welcome to the World
of Mashups
Simpo PDF Merge and Split Unregistered Version -
4 How to Do Everything with Web 2.0 Mashups
How to . . .
■ Sell Things with Mashups
■ Provide Information with Mashups
■ Create Art with Mashups

T
his chapter presents a few of the thousands of mashups you can find today on the Web. No
one knows how many other mashups live behind corporate firewalls, but, chances are, the
number is large. The mashups in this chapter were chosen to show the variety of the world of
mashups. Some of them are proofs-of-concept, others are works-in-progress, and others are
experiments. Others are actual, live products or marketing tools.
Mashups often provide visualization of information, and, frequently, that visualization is
in the form of interactive maps. The release of the Google maps API was a major factor in the
interest in mashups, in large part because so much information lends itself to mapping. As you
will see in later chapters of this book, new technologies grouped together as Web 2.0 and AJAX
are the building blocks of mashups. In conjunction with APIs such as Google mapping, eBay,
Yahoo!, Flickr, and others, you will soon be able to build your own mashups like the ones shown
in this chapter.
AJAX (Asynchronous JavaScript and XML)
AJAX (Asynchronous JavaScript and XML) is a term first used by Jesse James Garrett
in 2005. AJAX is generally considered to include JavaScript, XML, XHTML, DOM, and
XMLHttpRequest, all of which are technologies developed in the 1990s, some of them in
conjunction with Microsoft’s Remote Scripting project. Despite this plethora of technologies,
the principle is quite simple: a Web page can retrieve and display data without having to
refresh or reload the entire page. To do this, the page needs to have its own programming
logic (usually provided in JavaScript); it needs to be able to send a request for data (usually
done with XMLHttpRequest); and it also needs to be able to load, and then unload, data to
and from requests (usually done with XML, XHTML, and DOM).
The phrase “Web 2.0” was first used in 2004 by O’Reilly Media. Web 2.0 refers to the Internet
as a platform, as well as the growth of collaborative and sharing services, such as social
networking sites, wikis, and the like. programmableweb.com is a primary reference to mashups.
You can find mashups categorized by tags, as well as by technologies, on that site.
Simpo PDF Merge and Split Unregistered Version -
CHAPTER 1: Welcome to the World of Mashups 5
Sell Things with Mashups

Mashups can search a database for items that have known addresses. Figure 1-1 shows one of
the most basic of such searches: a real-estate listing service ( />site). This is a natural for mapping mashups, not only because the items being mapped are not
movable (they are houses), but also because the data are already in a searchable database. The
map has the controls you find in most of the mapping mashups: zoom controls; controls to move
the map (including sensitivity to mouse drags); and a choice of a map view, a satellite view, or a
hybrid view showing both. Markers indicate data points. In this case, you can click on a marker
to open an info window with text, as is shown for the 927 Roble Av address. You can also hover
the mouse over another marker (such as 888 Creek Drive) to display a pop-up window.
The legend in the lower-right of the map identifies two types of markers, based on when
data were last updated. Mapping APIs let you customize markers to provide yet another level of
information on a map.
FIGURE 1-1
Property Listing Maps
1
Simpo PDF Merge and Split Unregistered Version -
6 How to Do Everything with Web 2.0 Mashups
A mashup is likely to be seen by a self-selected group of people (such as those interested in
real estate in a certain area). This makes a mashup a good candidate for a service such as Google
Ads. Scrolled out of view at the bottom of the window shown in Figure 1-1 are several such ads.
The real estate business certainly predates mashups, but other opportunities for mashups
represent new businesses or new areas for an existing business to pursue. TutorLinker.com
( shown in Figure 1-2, lets you specify an area and an area of skill to find
tutors. This mashup uses the Google maps API, and it demonstrates the use of a link in an info
window.
FIGURE 1-2 TutorLinker.com
Simpo PDF Merge and Split Unregistered Version -
CHAPTER 1: Welcome to the World of Mashups 7
Figure 1-3 shows another aspect of mashups. It lets you search an area for various items,
but, as you can see from the tabs at the upper left, it will let you see listings from multiple
sources such as eBay, Wal-Mart, Amazon, and Craig’s List. Mapping, shopping, and comparative

mashups are among the most common. Whereas the real estate mashup and the tutor mashup
were designed to sell goods or services, mashups such as this are used either as a vehicle for
advertising to people interested in specific products or as a way of generating referral fees to the
mashup creator from services such as Amazon.
FIGURE 1-3 findnearby.net
1
Simpo PDF Merge and Split Unregistered Version -

×