Search

4/04/2006

Flickr API Example


//var_dum($xml) output
object(SimpleXMLElement)#1 (1) {
["photos"]=>
object(SimpleXMLElement)#2 (1) {
["photo"]=>
array(100) {
[0]=>
object(SimpleXMLElement)#3 (0) {
}
[1]=>
object(SimpleXMLElement)#4 (0) {
}
.........
[99]=>
object(SimpleXMLElement)#102 (0) {
}
}
}
}


function photo_url($p, $size='t', $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=79211125%40N00&api_key=YourAPIKey";

$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){
print photo_url($photo,'s');
// print $photo['title'];
}

沒有留言: