by Bhumi // Jul 27,2012 // 3 comments
Flickr is one of the biggest website for the photostreams and Flickr supports API which is a very easiest way to display photos on your website without having to worry about server bandwidth and performance.
Well,Today I am going to explain how you get photosets from the Flickr with the use of Flickr API.
First of all,Lets get the Flickr API.To get the Flickr API, you need to sign into Flickr and request for an API key. Now you have your own Flickr API
Next is how we get Flickr photosets with using Flickr API.Here, I am going to use cURL to get the data from Flickr. If you don’t want to go with cURL, you can use file_get_contents function.
Let’s have a look into the below code:
|
1 2 3 4 |
http://api.flickr.com/services/rest/? method=flickr.photosets.getList&api_key=YOUR_KEY &user_id=flickr_user_id&format=php_serial |
In above code, I have defined api_key, you need to replace your Flickr API key with which to sign your requests.Next, method, I used here is flickr.photosets.getList which is one method of Flickr to get a list of a Flickr’s photosets. Third parameter is the user_id of flickr account.Fourth parameter is the format and php_serial format which will return serialized PHP string with the data
|
1 2 3 4 5 6 7 8 9 |
/* cURL instialization */ $cl = curl_init(); curl_setopt ($cl , CURLOPT_URL, 'http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=YOUR_KEY&user_id=flickr_user_id&format=php_serial'); curl_setopt ($cl , CURLOPT_RETURNTRANSFER, true); curl_setopt ($cl , CURLOPT_CONNECTTIMEOUT, 5); $contents = curl_exec($cl); curl_close($cl); |
Here,To get the data,I have used PHP cURL functions.cURL is a library of allows us to communicate with other servers.curl_init is initialize the cURL handle.In CURLOPT_URL in curl_setopt,to put the url to fetch data by curl library.curl_exec is execute the curl and curl_close is to close the curl. With CURLOPT_RETURNTRANSFER as true means to return the contents in a variable instead of echoing them to the browser.
|
1 2 3 4 5 |
$data = unserialize($contents); if ($data['stat'] == 'ok') { //other desire stuff } |
Here, I have unserialize the contents fetched via API.That’s it. Now you can use fetched details of flickr photos to direcly display on site,even you can create slideshow,gallery etc.
Lets check out the output returned by above code
|
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 |
Array ( [photosets] => Array ( [page] => 1 [pages] => 1 [perpage] => 1 [total] => 1 [photoset] => Array ( [0] => Array ( [id] => xxxxxxxxxxxxxxxxx [primary] => xxxxxxxxxx [photos] => 4 [videos] => 0 [title] => Array ( [_content] => Test ) [description] => Array ( [_content] => testing purpose ) ) ) ) [stat] => ok ) |
That’s it.I hope this post will helpful.I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
To grab content from nested tags in PHP
Recently I am working with scraping of data from external url and for scraping we always need to use preg_match function to get matched data. READ MORE
Check Email address using Network Functions
Today we are going back to basics of PHP with a quick tutorial on how to check email address using network functions of PHP.Network functions READ MORE
WordPress site into maintenance mode Without Plugin
With explained hook function over here,you can make WordPress site in “maintenance mode” easily.This is useful if you want to test a design change or READ MORE
Get English Ordinal Number Suffix in PHP
A post after very long time. Actually busy with work,here i am going to share one quick post about how to get English Ordinal Number READ MORE
To Display XML content using PHP Header
Nowadays web services are become more and more popular and Most commonly used format for exchanging information in web services are XML because XML is READ MORE
Be a Contributor at CreativeDev.Write an article or tutorial to the community and share some of your knowledge!
Pingback: Wordpress Plugin: Cool Flickr Slideshow | Creative Dev
Pingback: Wordpress Plugin: Cool Flickr Slideshow | Creative Dev
Pingback: Wordpress Plugin: Cool Flickr Slideshow | CreativeDev