Fast and Rich Apps |
|
2024-11-24 |
|
|
9 |
|
|
Flickr also has a REST interface
REST Query to get public photos
http://flickr.com/services/rest/?method=flickr.people.getPublicPhotos&user_id=56053642@N00&api_key=...
Returned XML
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="1" perpage="100" total="2">
<photo id="39006009" owner="56053642@N00" secret="f2086066d5" server="33"
title="IMG_7564.JPG" ispublic="1" isfriend="0" isfamily="0" />
<photo id="39006000" owner="56053642@N00" secret="4ec57bd51f" server="28"
title="IMG_7551.JPG" ispublic="1" isfriend="0" isfamily="0" />
</photos>
</rsp>
We can parse it like this
<?php
function photo_url($p, $size='s', $ext='jpg') {
return "http://static.flickr.com/{$p['server']}/{$p['id']}_{$p['secret']}_{$size}.{$ext}";
}
$url = "http://flickr.com/services/rest/?method=flickr.people.getPublicPhotos".
"&user_id=56053642@N00&per_page=2&api_key=3aba8184848f9263b80795c95529bcd1";
$xml = @simplexml_load_file($url) or die("Unable to contact Flickr");
$perpage = $xml->photos['perpage'];
$total = $xml->photos['total'];
foreach($xml->photos->photo as $photo) {
echo '<a href="'.photo_url($photo,'o').'" target="_blank">';
echo '<img src="'.photo_url($photo).'" height="75" width="75" />';
echo '<br />'.$photo['title'].'</a><br />';
}
?>
Output