SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 241 | Next

Raymond Yee

"Pro Web 2.0 Mashups: Remixing Data and Web Services"

flickr.com/photos/7841384@N07/1153699093/
http://farm2.static.flickr.com/1023/1153699093_d1fba451c9.jpg
In the following sections, I??™ll show you how to instantiate that logic into code. Specifically,
we will write a simple third-party Flickr app in PHP that makes a Flickr API call and converts
the response to HTML. We??™ll use two important sets of techniques that I will elaborate on in
some detail, HTTP clients and XML processing, after which I describe how to use these techniques
to make the call to Flickr. Here I focus on PHP, but you can apply these ideas to your
language of choice.
?– Tip When debugging web services, I have found it helpful to use a network protocol analyzer such as
Wireshark (http://en.wikipedia.org/wiki/Wireshark). Properly formulating a web service call often
requires trial and error. Through its support of HTTP, Wireshark lets you see exactly what was sent and what
was received, including HTTP headers, response codes, and entity bodies.
HTTP Clients
Let??™s consider first the issue of how to perform an HTTP GET request and retrieve the response
in PHP. The function file_get_contents takes a URL and returns the corresponding content in
a string, provided the allow_url_fopen option is set to true in the system-wide php.ini. For
example:
// retrieve Atom feed of recent flower-tagged photos in Flickr
$url = "http://api.flickr.


Pages:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253