Integrating Flickr into my PHP web-app
I’m now to grab some photos from Flickr. Photos tagged with a given string and link to those images from my site.
I tried checking the Flickr API documentation but all it shows there are the available methods and their documentation. But with some poking around I finally found this page (http://www.flickr.com/services/api/auth.howto.web.html) which gives me the “how to’s” to get me started.
We’ll now need to download an API from the list. I initially picked-out the PHP5 API but after going through the doc, it turns out we need to make sure the CURL and SimpleXML extensions should be enabled. I’m not sure if that’s available on the target server so I’m going for the phpFlickr library for PHP4. It comes with some PEAR files but doesn’t really require you to have PEAR running on your server.
Below is a simple program to search for pictures having a particular tag (as I’m supposed to do with my site) :
<?
require_once(“phpFlickr.php”);
$f = new phpFlickr(“yourAPIkey”);
$result = $f->photos_search(array(‘tags’=>’rio’));
$photo = $result['photo'][0];
$info = $f->photos_getInfo($photo['id']);
print_r($info);
?>
What I’ll try to do now is to display the picture on my site. This is not on the standard documentation and from searching the internet I came across this solution. You should be able to access the picture from the Flickr site using a URL like this:
http://farm{farm_id}.static.flickr.com/{server-id}/{id}_{secret}.jpgorhttp://farm{farm_id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg
You’ll be able to get the farm_id, server-id, id and secret by executing the photos_getInfo which returns an array containing all info about about given picture_id. Using the code above we can add this line to display an image from Flickr:
echo “<img src=’http://farm{$info['farm']}.static.flickr.com/{$info['server']}/{$photo['id']}_{$info['secret']}_m.jpg’>”;
You should now be able to display a picture from Flickr. Have fun…
-
Recent
- My Move to the OSX (the dark-side)
- Skype & Apache conflict
- Simple yet effective way to replicate/mirror a database (any database at that)
- MySQL .frm recovery
- cakePHP calls crashing Apache
- Reformatting the default CakePHP layout (default.ctp)
- Syntax highlighting CakePHP using Eclipse
- Intersecting Entities on CakePHP Models
- Integrating Flickr into my PHP web-app
- Installing CakePHP
- Accessing a POP3 mailbox using PHP
-
Links
-
Archives
- October 2009 (2)
- April 2009 (2)
- February 2008 (1)
- January 2008 (6)
-
Categories
-
RSS
Entries RSS
Comments RSS