Recent Changes - Search:

Distributed Computing

This website demonstrates using wikis as teaching and learning tool.

The course instructor is also happy to share the teaching materials here with those who find it readable.

Access Flickr API with PHP

Introduction

Flickr is a photo-sharing community that enables users to upload hundreds of photos and tag each photo with descriptive words. Other users can then search on these tags, enabling them to find and comment on the photos of other users. Flickr's active community and addictive sharing features have attracted millions of users. Even better, Flickr exposes a rich set of Web services that make the service highly hackable.

Go to the following websites to know more about Flickr service and Flickr API


Activity One

Read Flickr API Fun from Rasmus' Toys page.

Activity Two

Study the following four PHP scripts.

  • flickr_api.inc
  • secrets.inc
<?php
$secrets = array('api_key'=>'24d52be90f046c1d2f05bbd2f47d4xxx','api_secret'=>'885384ffe42f4xxx');
?>
  • flickr_demo1.php
<?php
include 'flickr_api.inc';
include 'secrets.inc';
$flickr = new Flickr($secrets);
$photos = $flickr->peopleGetPublicPhotos('56053642@N00',null,50);
foreach($photos['photos'] as $photo) {
    $url = $flickr->getPhotoURL($photo);
    echo '<img src="'.$url.'" height="75" width="75" />';
}
?>
  • flickr_demo2.php
<?php
include 'flickr_api.inc';
include 'secrets.inc';
$flickr = new Flickr($secrets);
$u = htmlspecialchars($_REQUEST['u']);
?>
<html>
<head>
<title>Flickr Info for <?php echo $u?></title>
</head>
<body>
<?php
$nsid = $flickr->urlsLookupUser("http://www.flickr.com/photos/$u");
if(!$nsid) $nsid = $flickr->peopleFindByUsername($u);
if(!$nsid) $nsid = $flickr->peopleFindByEmail($u);

if(!$nsid) { echo "Unable to find $u"; exit; }

echo "<h2>Account Info:</h2>\n";
$info = $flickr->peopleGetInfo($nsid);
echo "<table border=0>\n";
foreach($info as $k=>$v) {
    if($k!='photos') {
        echo "<tr><th align=left>$k</th><td>$v</td></tr>\n";
    } else {
        foreach($v as $kk=>$vv) {
            if($kk=='firstdate') $d = date("(r)",(int)$vv);
            else $d='';
            echo "<tr><th align=left>Photos[$kk]</th><td>$vv $d</td></tr>\n";
        }
    }
}
echo "</table>\n";
$c = $info['photos']['count'];
if($c>500) $c=500;

$photos = $flickr->peopleGetPublicPhotos($nsid,NULL,$c);
if(!$photos) { $flickr->showError(); exit; }
$c = count($photos['photos']);

echo "<h2>Last $c photos of {$photos['total']}:</h2>\n";
foreach($photos['photos'] as $photo) {
    $thumb_url = $flickr->getPhotoURL($photo);
    $full_url = $flickr->getPhotoURL($photo,'o');
    echo <<<URL
<a href="$full_url"><img src="$thumb_url" border="0" height="75" width="75"></a>
URL;
    if(!(($i+1)%10)) echo "<br />\n";
}
?>
</body>
</html>

Activity Three

If you have a web server, put the above four files and experiment them.

Activity Four

Write a PHP code to get a list of photos tagged with cloud.

Questions

  1. What type of Web Services standards (REST or SOAP) that the program accesses? Explain your answer.
  2. What do you need if you want to run the above programs in your machine?
  3. Can you use the functions provided to upload your own photos to Flickr? If so, explain how. If not, explain why?
  4. Can you use the functions provided to search photos within a given geographical location? If so, explain how. If not, explain why?
  5. Can you use a Java program to implement the same functions? Explain your answer.
Edit - History - Print - Recent Changes - Search
Page last modified on January 16, 2009, at 05:34 PM