..


Sponsored Links

Flickr and PHP using APIs to interact with the class phpFlickr

Article written by Claudio Garau
Page 1 of 5

Flickr is a service made ​​available by the group Yahoo, the one that supplies the well-known search engine, for uploading and sharing images and video, including digital photos, Flickr works simply: you sign up, you uploaded the images and decide whether to share with everyone, only with some contacts or make them private.

To interact with Flickr via their web site provides a special class , called phpFlickr, released under an Open Source license and can be downloaded from this page, which provides methods and properties required to interface to the service.

Before moving to the code, it is important to emphasize that the developer intends to use phpFlickr, must have a figure that can be recovered from ' App Garden of Flickr, talk of 'API key that allows the user to authenticate their applications to the service.

Display images on a user

Once recovered, you can use the API Key for the instance of the class and for creating the phpFlickr; the following code shows how you can insert into a page of its website a few images taken directly from those stored in their own space on Flickr:

 



 <? Php







 / / Include class phpFlickr







 @ Include ("phpFlickr / phpFlickr.php");







 / / Instance of the class and object creation phpFlickr







 / / The argument is the Flickr API key







 $ Instance = new phpFlickr ("LATUAAPIKEY");







 / / Initialize the count for images

 





 $ Multi = 0;







 / / Extract the id corresponding to the user name







 $ Username = $ request-> people_findByUsername ('ILTUONOMEUTENTE');







 / / Extract the links to the images







 $ Link = $ instance-> urls_getUserPhotos ($ username ['id']);







 / / Definition of the number of images to be displayed ("20")







 $ Images = $ instance-> people_getPublicPhotos ($ username ['id'], NULL, NULL, 20);







 / / Loop to display images







 foreach ((array) $ images ['photos'] ['photo'] as $ image) {



  



 / / Link to the original



  



 echo "<a href=\"".$collegamento.$image['id']."\">";



  



 echo "<img border=\"0\" alt=\"".$image['title']."\" src=\"".$istanza-> buildPhotoURL ($ image," Square ")." \ ">";



  



 echo "</ a> \ n";



  



 / / Increment counter



  



 $ Multi + +;



  



 / / Number of images for each line ("3")



  



 if ($ mul% 3 == 0) {



    



 echo "\ n";



  



 }

 





 }







 ?>

 
To see pictures of your account, it is necessary that they are publicly visible, as you can see in the example above, the first thing to do to be for the inclusion of the class file, this is done, you will need to pass their API Key to the instance of the class itself, in order to create an object phpFlickr.

The next step is to go to method people_findByUsername (), user name which you want to show the images, so you can retrieve the id, that is the unique identifier of the account on Flickr.

The id will be used for the extraction of images, because the application uses the method people_getPublicPhotos () to collect the extracted files related to the identifier and make them available for viewing in the amount determined by the number passed to it as the last argument (in this case "20" pictures), will be available as an array that can be cycled for the creation of a tunnel along the lines of the following:

User Images

Note the use of the method buildPhotoURL () that retrieves the internal path of each image to Flickr.

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links