11
Aug
2009

Twitter LogoI'm pretty close to being done with my latest re-skinning effort of BlogCFC, and wanted to add a Twitter Pod to display my most recent tweet.

I've done some work recently with the Twitter API for blitztweets.com, so I didn't think it would be too difficult of a task.

I added a method to blog.cfc, added an application variable with the last update date/time (so as to only update every 'n' minutes and avoid potentially hitting the rate limit), and then created the pod itself (aptly named twitter.cfm).

After reinitializing the blog, everything looked good. I waited a few minutes, made a new tweet, and reloaded the page. Unfortunately, it didn't update.

I didn't realize that BlogCFC makes fairly extensive use of caching in order to keep page rendering times as responsive as possible. With the exception of the actual method that I placed in the blog.cfc file, most of the code was in the twitter.cfm page (the pod). This is where I did a dateDiff() on the application.tweetLastUpdated to see if I should make a new API call. The caching prevented all of this from happening as I had hoped.

My quick workaround was to create a ColdFusion scheduled task to hit the blog URL with the reinit variable every 5 minutes. A hack, but it worked. Obviously, it left a lot to be desired.

After some googling, I came across a JavaScript solution called tweet! that incorporates unobtrusive jQuery. There are a couple of advantages to going the JavaScript route:

  1. Bypasses BlogCFC's caching of ColdFusion code.
  2. Because requests are executing on the client, it's much less likely that I'll run into rate limiting issues. Twitter limits API calls from a particular IP address to 120 per hour. In theory, I would have been safe by caching the result and only updating every 5 minutes. But with each request coming from the client, it's all but impossible that I'll encounter rate limiting issues. Even if a particularly overzealous reader refreshes the page over 120 times in an hour, the rate limit would only apply to that IP/user.
  3. jQuery is awesome. Incorporating the plugin was a piece of cake. I downloaded the .js file to the appropriate directory, made some minor modifications to the file to tweak the look of the output, and that was it.

Given the popularity of Twitter, I thought others might find this useful as a quick and easy way to incorporate a Twitter Pod into BlogCFC.

Comments (1) | 1463 Views

Comments

Add Comment | Subscribe to Comments

  1. Swindon Air Con recharge's Gravatar

    # Posted Swindon Air Con recharge on 8/22/09 1:47 PM

    They say the best inventions/solutions are the simple ones - this has answered my problem before having to think about it too long. Many thanks!!

Add Comment