- file_get_contents: documentation ( source)
- unserialize: documentation ( source)
- print_r: documentation ( source)
- urlencode: documentation ( source)
- implode: documentation ( source)
<?php
# build the API URL to call
$params = array(
'api_key'=> "fd3fabe4e9d94ca725df1de71b8d285b",
'method'=> "flickr.photos.search",
'tags'=> "torre de belem",
'format'=> "json",
);
$encoded_params = array();
foreach ($params as $k => $v){
$encoded_params[] = urlencode($k).'='.urlencode($v);
}
# call the API and decode the response
$url = "http://api.flickr.com/services/rest/?".implode('&', $encoded_params);
print_r($url);
$rsp = file_get_contents($url);
$rsp_obj = unserialize($rsp);
# display the photo title (or an error if it failed)
if ($rsp_obj['stat'] == 'ok'){
$photo_title = $rsp_obj['photo']['title']['_content'];
echo "Title is $photo_title!";
}else{
echo "Call failed!";
}