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/.
- Callback value for stand-alone applications: oob, mentioned here.
- 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
- 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.
- 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.
- 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
- XML response received from Flickr may be read using Matlab XmlDOM functionality. I have a short separate post on it.
- Alternatively, one can obtain the response in the JSON format, using two additional parameters:
nojsoncallback = 1.