TechBrew

Informative geekery on software and technology

Twitter Hacks: Undocumented RSS and JSON features

March 17th, 2007 by Mark Woodman

twitter.pngMark Lozano (also of TechBrew) and I have been working on a Twitter-related experiment that we’ll reveal sooner or later.

In the meantime, I found a couple of undocumented (or at least really obscure) Twitter features that may prove useful to developers:

1) RSS feeds can also be JSON

At the bottom of a Twitter profile page is an RSS link with a URL that looks like this:

http://twitter.com/statuses/user_timeline/816092.rss

(The number in the URL is your member id, incidentally.) If you would like to write a client-site app which consumes that content as JSON instead of RSS, simply change the feed extension from “.rss” to “.json”:

http://twitter.com/statuses/user_timeline/816092.json

2) JSON with Ajax callbacks

It gets better: Twitter also lets you specify a method callback on any JSON feed. So if you’re doing Ajax with dynamic script tags, add your script’s method name to the URL like so:

http://twitter.com/statuses/user_timeline/ 816092.json?callback=statusCallback

When your script has finished loading the JSON, it will automatically call your method. If this approach to Ajax is unfamiliar to you, check it out ASAP, since you can do cross-domain requests without the need for a server-side proxy.

If you look carefully at the Twitter JavaScript badges, you’ll see how this works.

3) Specify item counts in both RSS and JSON

Marjolein Hoekstra at CleverClogs was wishing for RSS feeds that had more status items than the default. As it turns out, you can specify a count on either an RSS url or a JSON one:

http://twitter.com/statuses/user_timeline/816092.rss?count=19
http://twitter.com/statuses/user_timeline/816092.json?count=2

The resulting RSS or JSON will only have the number of status messages that you have specified. And yes, you can combine the callback parameter with the count, like so:

http://twitter.com/statuses/user_timeline/ 816092.json?callback=statusCallback&count=23;

Happy tweeting!

Trackback URI | Tags: How-To

4 responses so far ↓

Leave a Comment