Christian Heilmann

flickr.whois – using YQL to find Flickr user data from user ID or user name

Thursday, May 14th, 2009 at 2:24 am

One of the very frustrating things about Flickr is that there is a difference between user ID and user name when it comes to accessing the data via the API or even RSS. For example I can get to my home page via http://www.flickr.com/photos/codepo8 but the RSS feed url is http://api.flickr.com/services/feeds/photos_public.gne?id=11414938@N00&lang=en-us&format=rss.

The user name doesn’t work, you need the user ID (which is normally in the format of 11414938@N00). Getting this ID is not straight forward which is why there is the flickr.urls.lookupUser API method and several tools that do this for you.

However, I wanted to get more than just the ID from the name or the name from the ID. Using YQL, this was pretty easy.

I knew I could do a search for photos by providing the user id (try in console):


select * from flickr.photos.search(1) where user_id=”11414938@N00”

This returns a single photo and I can use its ID to get to the rest of my user data by reading out the owner (try this in the console):


select owner from flickr.photos.info where photo_id in
(select id from flickr.photos.search(1) where user_id=”11414938@N00”)

This returns all my user information which is cool, but I needed to find a way to match user name and ID. So I looked at the source code of my flickr page and found a hidden form field with the name “w” and the value of my nsid:

finding your nsid on the flickr homepage by  you.

Using this knowledge, I could get the NSID from a user name with a simple HTML scraper (try scraping in console)


select value from html where url=”http://www.flickr.com/photos/codepo8”
and xpath=”//input[@name=’w’]”

Putting this together, it was easy to build a JavaScript that returns the information for any user given an NSID or the user name:


var yql;
yql = ‘select owner from flickr.photos.info where photo_id in ‘+
‘(select id from flickr.photos.search(1) where ‘;
if(owner.indexOf(“@”)!==-1){
yql += ‘user_id=”’ + owner + ‘”’;
} else {
yql += ‘user_id in (select value from html where ‘+
’ url=”http://www.flickr.com/photos/’ + owner + ‘” and ‘+
‘xpath=”//input[@name=’w’]”)’;
}

yql += ‘) limit 1’;

Encased in a YQL execute table this can now be used to get the user data for either an NSID or a user name (try the open table in console).


use “http://isithackday.com/api/flickr.whois.xml” as flickr.whois;
select * from flickr.whois where owner=”sdeschamps”

Try it out:

If you want to shorten the results, add the “diagnostics=false” to the URL and use JSON as the output.

Share on Mastodon (needs instance)

Share on BlueSky

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

160: Graphs and RAGs explained and VS Code extension hacks Graphs and RAG explained, how AI is reshaping UI and work, how to efficiently use Cursor, VS Code extensions security issues.
159: AI pipelines, 10x faster TypeScript, How to interview How to use LLMs to help you write code and how much electricity does that use? Is your API secure? 10x faster TypeScript thanks to Go!
158: 🕹️ Super Mario AI 🔑 API keys in LLMs 🤙🏾 Vibe Coding Why is AI playing Super Mario? How is hallucinating the least of our worries and what are rules for developing Safety Critical Code?
157: CUDA in Python, Gemini Code Assist and back-dooring LLMs We met with a CUDA expert from NVIDIA about the future of hardware, we look at how AI fails and how to play pong on 140 browser tabs.
156: Enterprise dead, all about Bluesky and React moves on! Learn about Bluesky as a platform, how to build a React App and how to speed up SQL. And play an impossible game in the browser.

My other work: