skip to content

Easy Peasy: Using the Flickr API in Python

Since I'm often required to hit the ground running at $MPOW on projects, I was a little concerned when I roped myself into assisting our photo archives with a Flickr project. The first goal was to get a subset of the photos uploaded, and quickly. Googling and poking around the Cheeseshop led me to Beej's FlickrAPI for Python. Little did I know that it would be dead simple to get this project going. To authenticate:

def create_session(api_key, api_secret):
    """Creates as session using FlickrAPI."""
    session = flickrapi.FlickrAPI(api_key, api_secret)
    (token, frob) = session.get_token_part_one(perms='write')
    if not token:
        raw_input("Hit return after authorizing this program with Flickr")
    session.get_token_part_two((token, frob))
    return session

That was less painful than the PPD test for tuberculosis. Oh, and uploading?

flickr.upload(filename=fn, title=title, description=desc, tags=tags, callback=status)

Using this little code plus a few other tidbits, I created an uploader that parses CSV files of image metadata exported from an Access database. And when done, the results look a little something like this.

Comments

2 Comments

  • 💬 Jodi Schneider at March 27, 2008, 18:24 UTC:

    Beautiful, Mark! Any chance of enriching the tags?

    For instance, I'd like to be able to find
    Kepler by Kepler or Johannes, rather than Kepler, Johannes.

  • 💬 M.A. Matienzo at March 27, 2008, 19:02 UTC:

    I'd like to add this functionality, but it wouldn't be too easy to do automatically when you consider names like "Van de Graaff". I guess I could do some regular expression magic - I'll talk to my coworkers and see what they think.