flickr slideshows

The first part of doing this, though, was installing the Perl module for flickr. I don’t have root access on this account, and the admins were unresponsive, so I put in a local cpan setup using this article among others to set it up.

So, putting together bits and bobs, I now have the following test file:
[code lang=”perl”]
#! /usr/bin/perl -w

use Flickr::API;
use Data::Dumper;
use XML::Parser::Lite::Tree::XPath;

#use warnings;
#use strict;

my $debug = 0;

my $api = new Flickr::API({’key’ => ‘xxx’});
my $user = “yyy”;
my $response;

$response = $api->execute_method (’flickr.people.findByUsername’, {
‘username’ => $user,
});

$xpath = new XML::Parser::Lite::Tree::XPath($response->{tree});
@username = $xpath->select_nodes(’/user’);
$userid = $username[0]->{attributes}->{nsid};

$response = $api->execute_method (’flickr.people.getPublicPhotos’, {
‘user_id’ => $userid,
});

$xpath = new XML::Parser::Lite::Tree::XPath($response->{tree});
# url format:
# http://static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg
@photostream = $xpath->select_nodes(’/photos/photo’);
$totalphotos = @photostream;

for ($count=0; $count<$totalphotos; $count++)
{
$serverid = $photostream[$count]->{attributes}->{server};
$id = $photostream[$count]->{attributes}->{id};
$secret = $photostream[$count]->{attributes}->{secret};
print “http://static.flickr.com/$serverid/”.$id.”_”.$secret.”_m.jpg\n”;
#print “photo$count: server-id=$serverid\n”;
#print “photo$count: id=$id\n”;
#print “photo$count: secret=$secret\n”;
}
if ($debug)
{
print “Success: $response->{success}\n”;
print “Error code: $response->{error_code}\n”;
#print Dumper ($response);
print “Userid for $user is $userid.\n”;
print “$totalphotos public photos found\n”;
}
[/code]

I got the gist of this from the Linux Gazette, plus flickr has further information on their api methods and such.

The above code generates

http://static.flickr.com/56/139535670_a94bc9e450_m.jpg
http://static.flickr.com/46/139535669_a40fbe1dc4_m.jpg
http://static.flickr.com/51/139535668_ff8fc1a4b5_m.jpg

(These pictures are pretty much low-quality copies of individual pictures pulled out of the animated gif.) What I need to do is add in code that pulls only those that are tagged with a particular keyword, because I’m pretty sure I’m going to see other uses for this flickr account. But first, I’ll test this out…it pays to test along the way, so…

Pages: 1 2 3 4

del.icio.us:flickr slideshows  digg:flickr slideshows

1 Comment »

  1. Digital Ramble » Blog Archive » flickr api tip said,

    September 5, 2006 @ 12:49 pm

    […] In another quick and simple process, I personalized my About page a little with a bit of flickr html/java that they supply. Of course I’ve worked directly with their API, but in this case that’d be using a sledgehammer, since the good folks at flickr also provide a nice little javascript snippet to randomly select a couple of pictures/thumbnails to drop right in. I went to flickr’s badge generation page (logged in as moi, of course) to get started. […]

RSS feed for comments on this post · TrackBack URI

Leave a Comment

Bad Behavior has blocked 747 access attempts in the last 7 days.