My Story With Flickr
Upcoming SlideShare
Loading in...5
×
 

My Story With Flickr

on

  • 2,128 views

Just a simple story-mode how to work with the flickr api using the phpflickr class

Just a simple story-mode how to work with the flickr api using the phpflickr class

Statistics

Views

Total Views
2,128
Slideshare-icon Views on SlideShare
2,122
Embed Views
6

Actions

Likes
2
Downloads
7
Comments
0

2 Embeds 6

http://www.slideshare.net 5
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    My Story With Flickr My Story With Flickr Presentation Transcript

    • Using the flick r API to please my wife Background images downloaded from: http://profesorul09.webs.com/apps/photos/ My wife loves to take pictures, she also loves photo albums. Long time ago I wrote a little script for her that adds the original date to a photo using ImageMagick / This is the story of how to do the same in flick r Note: flick r automatically presents this info at the right side of any image – if it contains this EXIF info -, but I really want to try to do it by myself
    • Why Flickr? / Which language
      • Because its a very cool web application, supported for one of the most talented team into the Web Development scene. Also because it offers an open API that allows to do it.
      • JAVA for a desktop app sounds really sweet
      • PHP for a web app sounds good too
    • What does this app going to do?
      • Using a previously uploaded image get its original date (the date it was taken) and add it as a Tag / comment
    • How does it will look like?
    • This time I chose PHP
      • I want to put this as a simple on-line application, so I chose PHP as my language and start looking for a class that actually implements the flickr API ( http://www.flickr.com/services/api/ ). On the flickr page I found phpflickr ( http://www.phpflickr.com/ ) a very complete class, without special requirements (ie: you don't need to have PHP compiled with or without specific extensions), so you just need to download it to start using it
    • Flowchart – kind of
      • When the user loads the web application (from now on referred as just4fun) he/she will be required to start his/her flickr session. The reason for this is we want to gain access to all their images, and also, we want to write some info on them.
      • Once the user has logged into flickr is redirected to just4fun, when he/she can see a list of their albums.
      • The user click on any of their albums and gain access to the images inside of its selection.
      • The user click on any of the photos presented and just4fun add the date when the picture was taken as a comment and a tag inside flickr.
    • First Step: HTML Interface
      • Nothing special here, just one (kind of) cool trick, for my logo I used this: http://flickr.nosv.org/ an on-line application that creates logos with your text that looks like the flickr one. In my code I call the result as the source for my image:
      <img style=&quot;height: 84px; width: 369px;&quot; alt=&quot;just4fun - a simple app using flickr API&quot; src=&quot;http://flickr.nosv.org/out.php?s=just4fun&quot; align=&quot;left&quot; hspace=&quot;3&quot; vspace=&quot;1&quot;>
      • The rest of the code is just a couple of divs floating side by side
    • phpflickr – lets begin the magic!
      • The first great thing with this class is you don't really need to take care about the authentication process in flickr and how your user would be redirected. Phpflickr includes a callback script called auth.php that could serve you as the backbone for this process. You only need to configure it using your api key and your secret
    • auth.php $api_key = &quot; copy and paste your api key here &quot;; $api_secret = &quot; copy and paste your api secret here &quot;; $default_redirect = &quot;/&quot;; $permissions = &quot;read&quot;; $path_to_phpFlickr_class = &quot;./&quot;;
      • You don't need to change anything else in this file
    • In flickr ...
      • Now, assuming your application will be located on http://yourserver.com and you'll be using a lib subdirectory to store all the phpflickr files, you must define your callback url as: http://yourserver.com/lib/auth.php
    • And the index.php
      • Now let's take care of the index.php file, basically the only one the final user would see. First we need to call the class and use the auth.php script:
      <?php require_once(&quot;./lib/phpFlickr.php&quot;); require_once(&quot;./constants.php&quot;); $f = new phpFlickr(&quot;api_key&quot;,&quot;secret&quot;); $f->auth('write'); …
      • At this point we have a phpflicker object we could use for the rest of the steps
    • Get the albums
      • You can get all the albums for the authenticated user just using this: $albums = $f->photosets_getList();
      • Easy isn't?
      • And you can paint a list of albums with this couple of lines:
      foreach($albums['photoset'] as $album) echo &quot;<a href='&quot;.$_SERVER['PHP_SELF'].&quot; ?id_album =&quot;.$album['id'].&quot;'>&quot;.$album['title'].&quot;</a><br/>&quot;;
      • Look how I'm defining an href for every album than actually reloads the same page but passing an extra parameter id_album
    • For this album -> get the photos
      • Now, when the user selects an album, the index.php reloads and use the next lines to get all the pictures for this album:
      if($_GET['id_album']) $pictures = $f->photosets_getPhotos($_GET['id_album']);
      • And you going to paint all this pictures using something like this:
      $i = 0; foreach($pictures['photoset']['photo'] as $photo){ echo &quot;<a href='&quot;.$_SERVER['PHP_SELF'].&quot;?id_photo=&quot;.$photo['id'].&quot;'><img src='&quot;.$f->buildPhotoURL($photo, &quot;Square&quot;).&quot;' border='0'></a>&quot;; if($i>=3){ //only needed if you want rows of 4 photos each echo &quot;<br/>&quot;; $i=0; } else $i++;
    • For this photo -> get the date and use it as a comment/tag
      • At this point the user has selected a picture, and we have its id as a the parameter: id_photo, so for this photo we're going to get its EXIF date taken field and then we're going to use this date as a comment and a TAG
      • Step 1: get the information for this photo:
      $photo_info = $f->photos_getInfo($_GET['id_photo']);
    • For this photo -> get the date and use it as a comment/tag
      • Step 2: extract the date taken and use it as comment/tag
      $date_taken = $photo_info['dates']['taken']; $f->photos_addTags($photo_info['id'],$date_taken); $f->photos_comments_addComment($photo_info['id'],&quot;Taken on: &quot;.$date_taken);
    • Verify if everything works as expected if($f->getErrorCode()) echo $f->getErrorMsg(); else echo &quot;<a href='&quot;.$photo_info['urls']['url'][0]['_content'].&quot;' target=_blank title='Click on the image to open it on flickr'><img src='&quot;.$f->buildPhotoURL($photo_info,&quot;Small&quot;).&quot;' border='0'></a><br/><em>Your image was sucessfully Commented/Tagged</em>&quot;;
    • Original photo (real snapshot)
    • Process finished (real snapshot)
    • Commented Photo (real snapshot)
    • And that is – pretty much – all folks!
      • You can test this app on-line here: http://just4fun.jamslug.com
      • And if you're interested you can download and take a look of the full code of this app here: http://www.easy-share.com/1905396148/just4fun.zip
      • You can reach me via twitter: @lacucaramacara
    • Thanks for your attention Jose Andres Martinez S. http://thewebdevelopers.biz @lacucaramacara