Blogger Hacks, Categories, Tips & Tricks

Wednesday, February 08, 2006
Harnessing the Tagosphere - Redux
Psychologists say that shame is the most powerful human emotion. Well, I wouldn't be too quick to write off spite. During last month's del.icio.us upgrade, a valuable means of tapping into the hivemind of taggers was inexplicably turned off. I vowed revenge and today has seen the generic JSON feed return, with all the elegance, robustness and civic-mindedness of a dodgy third world electricity hookup.

First, the backstory. Perhaps the most important part of "social bookmarking" is the "social" bit. This means you can access the whole community's bookmarks, for example:

http://del.icio.us/tag/blogger

Note that no particular account is specified - here I'm asking for all pages tagged "blogger" by anyone. (Hence the term "generic".) Delicious, in their wisdom, allowed users to get at this information by publishing it as a JSON feed.

http://del.icio.us/feeds/json/tag/blogger

This feed format is a super-lightweight replacement for XML, like RSS without the trimmings. It's also what FreshTags uses to support in-blog navigation. This opened up a raft of novel and experimental uses of tag-driven content to enhance boring static pages. Freed from the restrictions of nominating a target delicious account or a pre-ordained set of tags, users could serve up a sidebar full of fresh links based on inbound search queries or free-form text entry by readers. We were just getting started and more exciting and disruptive possibilities were open.

But then Black Sunday fell. Delicious "upgraded" to Yahoo! machines, went up and down for days and eventually stabilised. From the wreckage, it was apparent that the generic JSON feeds had stopped working. Oh no! (Yet, strangely, they were still happily serving up generic queries as HTML and RSS.) A lone, plaintive voice spoke up in defence of JSON, but Joshua denied that it had ever worked at all. Inflamed, I stuck out my bottom lip, let it quiver, stamped my feet but to no avail: they were gone, weren't coming back and no one seemed to care. After sulking for a few weeks, I decided to take it back.

Step One. Locate a RSS2JSON conversion service. This is where I offer a thousand thanks to the pioneering work of John Resig - who, I might add, has a very powerful Javascript framework in jQuery. He offers a conversion service that (unsurprisingly) takes an RSS feed and converts it into its JSON equivalent. It looks like this:

http://ejohn.org/apps/rss2json/?url=URL&callback=CALLBACK

Where URL is the required RSS feed (in my case, http://del.icio.us/rss/tag/*) and CALLBACK is the name of your Javascript callback function.

Step Two. Write a suitable callback function. What's this? Well, it's a function that gets wrapped around your JSON object before being sent back to your page by ejohn's app. I called mine delify() since its job is to take the ejohn-style JSON object and convert it into the delicious-style JSON object. This just involved mangling things around and renaming. For example, "link" becomes "u", "title" becomes "d" etc.

Now that the resulting JSON object is indistinguishable from what delicious used to return, FreshTags can quite happily tear it apart, put it back together and render it nicely on your page. Check it out:

http://ghill.customer.netspace.net.au/

Or, tag-fixed to "blogger"

http://ghill.customer.netspace.net.au/?tags=blogger

Or, to try tag-grabbing, select a tag from the left on this blog and then visit my homepage.

Astute readers will notice that you can enter whatever text you like in the field and FreshTags will process it (via delicious and ejohn) asynchronously. That's right, no more reloading the page each time you change tags! This is a sneak preview of what's coming up in the next release. NB: I probably haven't done it quite right, so advice from seasoned AJAXians would be appreciated (privately please; no need to publicly run me down :-)

Sadly, I have to point out that I won't be incorporating ejohn's hosted rss2json hack into the next release of FreshTags, owing to the unfair burden on his servers and link. So this one-off implementation remains on my homepage as a form of silent protest, as well as a proof-of-concept. If you'd like to see this generic mode return to FreshTags, please lobby delicious to turn feeds/json/tag/* back on, or persuade your favourite bookmarker to go JSON, or even offer to host ejohn's rss2json yourself!

That said, it is reassuring to know that such a service is in principle available (John Ressig's code is released under a Creative Commons licence). This is especially important given the rise of a range of social bookmarking services offering RSS feeds - but not JSON.

Perhaps this finally frees FreshTag users from the hegemony of delicious ...

Update: John "ejohn" Resig wrote to inform us that his service sometimes gets temporarily banned by delicious, for making too many hits. Also, it doesn't seem to handle tag intersections too well. So best use one tag at a time and if it's down, try again the next day.


Filed in: , , , , , ,
Posted at 11:19 PM by Greg.
5 Comments:
<    >
Blogger Aditya said...
woah! that asynchronous loading of the tags on your homepage looks sweet!!

I would most certainly put up a petition post at del.icio.us, if i can just make sense of this whole business. You say del.icio.us doesn't support JSON...

So, then what is this?
We can carry on the conversation on GMail if you come online! :P

<    >
Blogger Aditya said...
err... i just realised you don't have a GMail account! :P so cut the last line out! :)

<    >
Blogger Greg said...
Hi Aditya,

Yes, they do support JSON:

http://del.icio.us/feeds/json/jrfj44/freshtags

But only for individual accounts. If you try to get everyone's bookmarks, you can't. Used to be able to, but now they've turned it off.

http://del.icio.us/feeds/json/tag/freshtags

You can still get everyone's bookmarks as an RSS feed, though:

http://del.icio.us/rss/tag/freshtags

This hacks take that RSS feed and pumps it through ejohn's rss2json converter and let's FreshTags carry on normally.

Hope this helps!

BTW, I do have a gmail address. While I don't publicise it, you could probably guess it. (HINT: you need to use the full Anglo-Celtic version of "greg" :-)

-Greg.

<    >
Blogger Aditya said...
Ah! I had a vague idea that that was what you meant when you said del.icio.us doesn't support generic JSON.

Since that is cleared up, it means asynchronous loading of the titles after tag selection can still be implemented, since JSON for individuals is supported?

When is the next version (hopefully with async loading) coming out? (tentatively?)

<    >
Blogger Greg said...
Yes, that's right. FreshTags will be going asynch, plus with blogrolling. Release date is hopefully this month, though my PhD has a way of rudely imposing itself in my life from time to time. (Less than 60K words to go now. Yeah!)

Links to this post:

Create a Link


eXTReMe Tracker