i have php code retrieves set of images based of photoset. want manipulate code grabs set of pictures search term.
i know can use method inbuilt api: flickr.photos.search
just wondering how can apply code
<?php $params = array( 'api_key' => '2292bec0973f91d9f62fb606f85ee031', 'method' => 'flickr.photosets.getphotos', 'photoset_id' => '72157622566216264', 'extras' => 'original_format', 'format' => 'php_serial' ); $encoded_params = array(); foreach ($params $k => $v){ $encoded_params[] = urlencode($k).'='.urlencode($v); } $ch = curl_init(); $timeout = 5; // set 0 no timeout curl_setopt ($ch, curlopt_url, 'http://api.flickr.com/services/rest/?'.implode('&', $encoded_params)); curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt ($ch, curlopt_connecttimeout, $timeout); $file_contents = curl_exec($ch); curl_close($ch); $rsp_obj = unserialize($file_contents); if ($rsp_obj['stat'] == 'ok') { $photos = $rsp_obj["photoset"]["photo"]; echo " <ul>"; foreach($photos $photo) { $farm = $photo['farm']; $server = $photo['server']; $photo_id = $photo['id']; $secret = $photo['secret']; $photo_title = $photo['title']; echo '<li><img src="http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].'_t.jpg" alt="'.$photo['title'].'" ></li>'; } echo " </ul> "; } else { echo "error getting photos"; } ?>
did read documentation? flickr.photos.search
these methods return similar data, name of top-level array different (photos vs. photoset). assuming modified parameters use correct method , pass appropriate arguments, other thing need change line:
$photos = $rsp_obj["photos"]["photo"];
Comments
Post a Comment