Learning to Download Flickr Photos Using Python and FlickrAPI

This was a quite tricky thing for me to get it running but here it is – how I download photos of a set (album) on Flickr (both public and private) with a python script to a Raspberry Pi.

Getting Flickr User ID, API-Keys and set ID

To get my Flickr user ID I lock into my Flickr account and go to my photostream. I will find an URL in my browsers address field such as:

14XXXXXX3@NXX is my user ID

To get my Flickr API-Keys I go to: https://www.flickr.com/services/apps/create/apply/

I chose non-commercial key as I wanted to use it for a private project.

I was provided with both an API-key and a secret key that might look something like this:

To get the Flickr album’s ID of which I wanted to download the photos I went to that album in a browser and got an URL like this:

721XXXXXXXXXXX0166 is my photo set’s (album’s) ID

Installing Python Packages

On my Raspberry Pi (or whatever system I’m running my Python on) I need to install several packages to beeing able to work with flickr_download 0.2.14.

In the documentation of this package I’m asked to install:

Installing argparse

I installed this by using this command:

sudo gives me super user rights (take care to not mess up your system using this!)
pip is the command to tell python to install or deinstall something (python install package)
install installs the following package
argparse was the package I wanted to install

Installing Python Dateutil

I could have installed this by using the following command. It was already installed though.

sudo gives me super user rights (take care to not mess up your system using this!)
pip is the command to tell python to install or deinstall something (python install package)
install installs the following package
dateutil would have been the package I wanted to install

Installing Python Flickr API

I installed this by using this command:

sudo gives me super user rights (take care to not mess up your system using this!)
pip is the command to tell python to install or deinstall something (python install package)
install installs the following package
flickrapi was the package I wanted to install

Installing PyYAML

I installed this by using this command:

sudo gives me super user rights (take care to not mess up your system using this!)
pip is the command to tell python to install or deinstall something (python install package)
install installs the following package
http://pyyaml.org/download/… was the path to the package’s archive I wanted to install, as sudo pip install pyyaml returned the error this package couldn’t been found.

Installing flickr_download

I installed this by using this command:

sudo gives me super user rights (take care to not mess up your system using this!)
pip is the command to tell python to install or deinstall something (python install package)
install installs the following package
https://pypi.python.org/packages/… was the path to the package’s archive I wanted to install, as sudo pip install flickr_download returned the error this package couldn’t been found.

Get OAuth-Verifier

I needed to get an oauth verifier Token using the flickr_download script with authentication for the first time. Authentication was needed though as I wanted to also download my private pictures.

I ran the script as described in the package’s documentation as follows:

flickr_download calls the script
-k <api key> sets my public API-key
-s <api secret> sets my secret key
-d <set id> defines the album (or set) of my Flickr Stream I want to download
-t calls for authentication

An URL was displayed and I was asked to copy that URL into my browser’s address field. This printed some XML code which contained my <oauth_verifier> I was asked for. I copied and pasted this back into my terminal, hit enter and had to rerun the script to download all my set’s photos.

 

Resources I’ve Been Using to Learn This

https://pypi.python.org/pypi/flickr_download

https://www.flickr.com/services/apps/create/

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 17 =