Backing up your flickr account with Perl (not for the faint of heart)
[NOTE: see the first comment below, I added a script to get the auth_key for you.]
Today I decided that I would like to backup my flickr account to my Mac. After a few attempts at using a Java based UI tool "FlickrBackup", which had terrible network performance for some reason, I fell back to my trusty old Perl skills.
Here is what I did:
1. Install Net::Flickr::Backup
To install this module, open up a terminal and type:
cpan
When CPAN loads up, type:
install Net::Flickr::Backup
Its pretty much that easy.
2. Go to Flickr.com and create an API key. Create one for a web application, and enter pretty much any valid url as your callback. I know, its not a web application...just do it, k?
3. Get an auth_token. This is harder than it needs to be, but here is how I got it done:
- First get a frob. This page shows you how to do it manually. Mac OS X has a terminal command, "md5" that you can run to make your api_sig value. for example:
md5 -s 000005fab4534d05api_key9a0554259914a86fb9e7eb014e4e5d52permsread
Which would yield a MD5 hash of: f2c52fb8fd3124314227bbc0f48003d3
Which it turn would mean the auth url needs to be like:
http://www.flickr.com/services/auth/?api_key=9a0554259914a86fb9e7eb014e4...
Once the URL is constructed, paste it into a browser, and approve access to your account. Once you approve, flickr calls your callback url. I just made my callback a bogus url like http://mattmackenzie.com/authdummy/
The frob will be in the URL that flickr redirects to. Copy it from your address bar, and vist this page. Paste the frob into the input value box, make sure "sign url with
Next, create a file called flickr_backup.cfg, and type the following into it:
[flickr] api_key=API KEY api_secret=SECRET auth_token=AUTH TOKEN api_handler=LibXML [backup] photos_root=/Path/Where/You/Want/Photos/BackedUp [rdf] do_dump=true rdfdump_root=/Path/Where/You/Want/Photos/rdf
and another file named flickr_backup.pl that is like this:
#!/usr/bin/perl
use Net::Flickr::Backup;
use Log::Dispatch::Screen;
my $flickr = Net::Flickr::Backup->new("/path/to/flickr_backup.cfg");
my $feedback = Log::Dispatch::Screen->new('name' => 'info',
'min_level' => 'info');
$flickr->log()->add($feedback);
$flickr->backup();
Now, just run it: perl flickr_backup.pl
I'll clean this up some time when I get some spare cycles, so sorry about the bad formatting and sketchy instructions.





Update...
I wrote a script to help you get the API key. THIS CODE REQUIRES THAT THE API KEY BE OF THE "Desktop" VARIETY...not the web variety as is suggested above. If you want to do it the manual way, leave the key as a web app key.
Here it is:
# Written by Matt MacKenzie, matt AT mattmackenzie DOT com.
use Flickr::API;
use Flickr::API::Response;
# CONFIG: FILL THESE IN
my $key = '';
my $secret = '';
# END STUFF YOU NEED TO MESS WITH.
my $api = new Flickr::API({'key' => $key,
'secret' => $secret});
my $response = $api->execute_method('flickr.auth.getFrob');
my $frob = $response->{tree}->{children}->[1]->{children}->[0]->{content};
$auth_url = $api->request_auth_url('read', $frob);
print "Please visit: " . $auth_url . " and then press.\n";
my $enter = <>;
$response = $api->execute_method('flickr.auth.getToken', {'frob' => $frob});
my $auth_key = $response->{tree}->{children}->[1]->{children}->[1]->{children}->[0]->{content};
print "Your auth key is: " . $auth_key . "\n";
Error
Hello,
Everything was going fine so far :
root ~ # ./flickr_backup.pl
Can't call method "param" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/Net/Flickr/API.pm line 159.
I looked at the line:159 ;
if ($self->{cfg}->param("flickr.api_handler") !~ /^(?:XPath|LibXML)$/) {So I suppose, I misconfigured this line :
api_handler=LibXMLWhat do i need to write on this line ?
Thx :-),
Martin
Do you have LibXML
Do you have LibXML installed?