|
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. |
Tutorial /
Access Flickr API with PHPIntroductionFlickr 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 OneRead Flickr API Fun from Rasmus' Toys page. Activity TwoStudy the following four PHP scripts.
<?php $secrets = array('api_key'=>'24d52be90f046c1d2f05bbd2f47d4xxx','api_secret'=>'885384ffe42f4xxx'); ?>
<?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" />'; } ?>
<?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 ThreeIf you have a web server, put the above four files and experiment them. Activity FourWrite a PHP code to get a list of photos tagged with cloud.
Questions
|