Skip to main content a tiny command-line tool for exploring the Flickr API

I use the Flickr API pretty much every day in my day job. Within the first week, I bashed together a couple of command-line tools to make a simple tool for exploring the API. They’re not meant for building “proper” apps, more for quick experiments and seeing what API responses look like.

The main tool is flapi, and you pass it two arguments: the name of the API method, and (optionally) any query parameters you want to include. Then it calls the Flickr API for you!

For example:

$ flapi photo_id=25260341744
<?xml version="1.0" encoding="utf-8"?>
<rsp stat="ok">
  <photo id="25260341744" secret="3e30df4a20" server="1645" farm="2" dateuploaded="1458345230" isfavorite="0" license="7" safety_level="0" rotation="0" originalsecret="b473e4a3b0" originalformat="jpg" views="83654" media="photo">

There are lots of ways to play with APIs – colleagues at a previous job used Postman, and Flickr itself has an API Explorer where you can try requests in the browser. I like doing it with a command-line tool because I always have lots of terminal windows open, and it’s easy to grab one and check something with flapi.

Today I finally took the time to tidy up the script and post it on GitHub.

The code isn’t complicated – indeed, it was easy to cobble it together from a bunch of other tools. Even if you have no interest in the Flickr API, some of them might be useful for you.

Put together, the core logic of flapi is just four lines:

api_key=$(keyring get flickr_api key)

curl --silent "${api_key}&method=${method}&${params}" \
  | xmllint --format - \
  | pygmentize -l xml

These four programs feel like an exemplar of the Unix Way: small tools that each do one task well, written so they can be combined in complex ways.