Flickr photo hosting service provides an extensive API allowing for full control over the image files, tags, contacts, notes etc. Language-specific API’s are available for many programming languages (see http://www.flickr.com/services/api/). In a small tutorial (http://www.mathworks.com/matlabcentral/fileexchange/34162) I have shown how to use Flickr API in Matlab.

There are a few tricks to use when developing an app using Flickr API. They are not nicely described by Flickr (as of December 2011) and it takes some effort to find out how to do some simple things. Here I will be collecting the solutions.

I’d like to thank Sam Judson’s for help on the way to coping with Flickr’s OAuth. More information on Flickr OAuth can be found in his tutorial: http://www.wackylabs.net/2011/12/oauth-and-flickr-part-1/.


  1. Callback value for stand-alone applications: oob, mentioned here.
  2. When using urlread function of Matlab, in case something did not work as expected, Matlab shows a rather useless error message “Error using urlread (line 113). Error downloading URL. Your network connection may be down or your proxy settings improperly configured.” This is actually not at all what happens. In order to see what actually happens, paste the request line generated by the code (passed to urlread function) to the browser. Flickr will give a response explaining what it does not like, e.g.
    oauth_problem=timestamp_refused (check that your time is the Unix epoch time, in seconds, and that it’s UTC, not your local time),
    oauth_problem=nonce_used (each request to Flickr should have a unique random string identifier), or oauth_problem=signature_invalid&debug_sbs=GET&http%3A%2F%2Fwww.flickr.com...
  3. If you get the signature invalid error, it means that your request is generally correct but the signature is wrong. This is a tough problem since any tiny error in the base string algorithm will completely spoil the signature. To help resolving this issue, Flickr provides its own version of the base string, which you can compare to yours. I usually compare them in a Notepad by pasting the two strings one below another. The rules of building the base string are explained by Flickr and also in my tutorial.
  4. OAuth signature looks like a random string so it’s hard to debug. Therefore before searching for other problems in your code, make sure that your signature generation algorithm works correctly. You can compare it to this online signature generator: http://hash.online-convert.com/sha1-generator.
  5. Base string to be signed should be url-safe. Matlab provides function urlencode. Beware: it should be followed by
    s = strrep(s, '+', '%20')
    because of two versions of such encoding. See http://www.albionresearch.com/misc/urlencode.php
  6. XML response received from Flickr may be read using Matlab XmlDOM functionality. I have a short separate post on it.
  7. Alternatively, one can obtain the response in the JSON format, using two additional parameters: format=json and nojsoncallback = 1.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s