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 Twitter

Newsletter

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

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: