TweetTicker: read Twitter Atom/RSS with NewsTicker and ColdFusion
The other day at work I decided see what could be done with Twitter Atom/RSS feeds. I wanted to be able to have a scrolling vertical 'ticker' of Tweets, but without having to use Twitter's developer API.
I did a quick Google search to see what pre-built tools I might be able to pull together and use and came across NewsTicker, a Javascript tool based on the MooTools Javascript framework. It was being used for News items, hence the name, but had the same functionality I had been looking for to display Tweet items.
So, using NewsTicker and ColdFusion's <CFFEED/> tag to easily grab my Twitter feed I was quickly and easily able to put something together in no time.
To make sure this post does not go into too unnecessary detail, I've provided a link to both a demo and and ZIP archive at the bottom of this post incase anyone would like to modify it for their own needs. My example is of course fairly basic and simply an experiment so I'm sure you can make it more advanced without any trouble :-).
Some things worth noting:
Since I am in Australia, I had to convert the date/time values retrieved from the Atom/RSS feed to a relative time reference based on my time zone.
<!--- Set Locale: --->
<cfset setLocale("English (Australian)") />
<!--- Apply timezone offset of hours: --->
<cfset pubDateTime = DateAdd("h",-GetTimeZoneInfo().UTCHourOffset,pubDateTime) />
I then needed to format my date/time value to show a value relative to 'now'. I used Ray Camden's Relative Time UDF:
<cfscript>
function relativeTime(pastdate) {
var delta = dateDiff("s", pastDate, now());
if(delta < 60) {
return "less than a minute ago";
} else if(delta < 120) {
return "about a minute ago";
} else if(delta < (45*60)) {
return round(delta/60) & " minutes ago";
} else if(delta < (90*60)) {
return "about an hour ago";
} else if(delta < (24*60*60)) {
return round(delta/3600) & " hours ago";
} else if(delta < (48*60*60)) {
return "1 day ago";
} else {
return round(delta/86400) & " days ago";
}
}
</cfscript>
To get the feed from Twitter I used:
<!--- Default the Twitter user you would like to use: --->
<cfparam name="url.twitterUser" default="nothingwithyou" />
<!--- Set Twitter Atom/RSS feed URL: --->
<cfset feedurl="http://search.twitter.com/search.atom?q=#url.twitterUser#" />
<!--- Get Twitter RSS feed for the intended user: --->
<cffeed
source="#feedurl#"
properties="feedmeta"
query="feeditems" />
It is quite easy to choose either the Atom or RSS feed to read, by simple changing part of the URL string from "search.atom" to "search.rss".
Anyway, check out the demo and source and see how it goes. When viewing the demo, if you have a Twitter account or know of one you like, try adding:
?twitterUser={twitter_account_name_here}
to see the reader pick up that account's feed.
Note: I am running ColdFusion 8
Note: Functionality for refreshing Tweet items in the Demo and Source Code has been removed.
Edit:
Additional Twitter API search examples (ensure URL encoding):
- Containing a word: http://search.twitter.com/search.atom?q=twitter
- From a user: http://search.twitter.com/search.atom?q=from%3Aal3x
- Replying to a user (tweet starts with @mzsanford): http://search.twitter.com/search.atom?q=to%3Amzsanford
- Mentioning a user (tweet contains @biz): http://search.twitter.com/search.atom?q=%40biz
- Containing a hashtag (up to 16 characters): http://search.twitter.com/search.atom?q=%23haiku
- Combine any of the operators together: http://search.twitter.com/search.atom?phrase=happy+hour&until=2009-03-24
- Originating from an application: http://search.twitter.com/search.atom?q=landing+source:tweetie
There is so much you can do via the API's search function (additional parameters, boolean operators, Curl/ JSON response formating), check it out here: Twitter API Wiki: Search Method
TweetTicker: read Twitter Atom/RSS with NewsTicker and ColdFusion


