1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
function getPhotosNikon (){
//Préparation de la requête
$base_url="http://api.flickr.com/services/rest?";
$query_string="";
$params= array(
"method" => "flickr.photos.search",
"api_key" => "",
"tags" => "nikon35mm");
$query_string .= http_build_query($params);
$url = $base_url.$query_string;
//Envoie de la requête et reception de la reponse
$client = curl_init($url);
curl_setopt($client, CURLOPT_RETURNTRANSFER, 1);
$reponse = curl_exec($client);
curl_close;
//Traitement de la réponse
$xml = simplexml_load_string($reponse);
foreach ($xml->photos->photo as $photo) {
$attributs = $photo->attributes();
$image_url = 'http://farm'.$attributs['farm'].'.static.flickr.com/'
.$attributs['server'].'/'.$attributs['id'].'_'.$attributs['secret'].'.jpg';
echo '<a href=http://www.flickr.com/photos/'.$attributs['owner'].'/'
.$attributs['id'].'><img src="'.$image_url.'"/><br / ></a>';
//Préparation de la requête pour récupérer les infos de chaque photos
$query_string_info = '';
$params_info = array(
'method' => 'flickr.photos.getInfo',
'api_key' => '',
'photo_id' => $attributs['id'],
'secret' => $attributs['secret']);
//$query_string_info .= 'method=flickr.photos.getInfo&api_key=290a35fd4c6a80bb6e738c02a06dce24&photo_id='.$attributs['id'].'&secret='.$attributs['secret'];
$query_string_info .= http_build_query($params_info);
echo '<br />'.$query_string_info.'<br />';
$url_info = $base_url.$query_string_info;
echo $url_info.'<br />';
//Envoie de la requête
$client_info = curl_init($url_info);
curl_setopt ($client_info, CURLOPT_RETURNTRANSFER, 1);
$reponse_info = curl_exec($client_info);
curl_close($client_info);
//Traitement de la reponse
$xml_info = simplexml_load_string($reponse_info);
echo $xml_info;
//print_r($xml_info);
//Affichage des infos
echo '<br />'.$xml_info->photo->description.'<br />';
}
} |
Partager