In my search for finding a simple solution to any problem, I usually cross many and many blogs and articles, discussing whatever topic. But with so much detail that the solution becomes a problem in itself. So I often times end up resolved to research on my own. In this case, I share the simplest programming method for displaying a Flickr gallery, with PHP.
Assembling Your Variables
1 2 3 4 5 6 7 8 9 10 11 12
$api_key is part of an authentication device that allows your server and Flickr to “shake hands” sort of speak. You can get your Flickr API key here.
$user_id is how Flickr identifies you. This value can be found in the URL of your Flickr “photostream”. Here’s mine for reference.
$per_page refers to how many photos will be retrieved from your photostream. Though this limiter is optional, the default count is, “all”. Which means if you have 1,000 plus photos, it could be a very bad thing, for your viewer’s browser load time.
$xml is a link to the webfile that renders a list of your available photos based on previously noted variables. This line can be modified later to include even more search parameters. (see: below)
$flickr uses a PHP function called, simplexml_load_file(), which parses an XML file into an object.
In today’s lesson, $flickr becomes an array and we use foreach() to extract the values we need, to display the gallery.
This method is just what I needed. Something small, easily accessible, and scalable. As you experiment with this script, you’ll be afforded the opportunity to use many different features of the API, which Flickr offers. Click here to view a full list.