Skip to content

Instantly share code, notes, and snippets.

@avinashbangar
Created November 6, 2010 06:44
Show Gist options
  • Save avinashbangar/665243 to your computer and use it in GitHub Desktop.
Save avinashbangar/665243 to your computer and use it in GitHub Desktop.
Getting photos from Flickr using YQL
<!-->
Following code gets information about photos from Flickr via YQL for the given search term
Author : avinash
Email : [email protected]
<-->
<h2>Using YQL to Access the Flickr API</h2>
<form name='upcoming_form'>
Search: <input name='keyword' id='keyword' type='text' size='20'/><br/>
<p><button id='find_event'>Find Photo</button></p>
</form>
<?php
$yql_base_url = "http://query.yahooapis.com/v1/public/yql";
if(isset($_GET['keyword'])){
$keyword = $_GET['keyword'];
//query for searching photo and getting related information to it
$yql_query = "select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where text='$keyword')";
//generating url
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
//getting the result output in json format
$yql_query_url .= "&format=json";
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
$flickrObj = json_decode($json);
foreach($flickrObj->query->results->photo as $photo) {
echo "<br/>";
echo "ID : ".$photo->id;
echo "<br/>";
echo "Title : ".$photo->title;
echo "<br/>";
echo "Description : ".$photo->description;
echo "<br/>";
echo "Uploaded Date : ".$photo->dateuploaded;
echo "<br/>";
echo "Owner : ".$photo->owner->realname;
echo "<br/>";
echo "Photo Taken On : ".$photo->dates->taken;
echo "<br/>";
echo "Link : ".$photo->urls->url->content ;
echo "<br/>";
//generate url for display photos of size medium
$url = $source = "http://farm".$photo->farm.".static.flickr.com/".$photo->server."/".$photo->id."_".$photo->secret."_m.jpg";
?>
<img src=<?php echo $url; ?>>
<?php
}
}
unset($_GET);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment