Skip to content

Twitter Integration

I’ve been using Twitter for the last couple of weeks, mostly to see what the fuss was about and to see how/if I’d use it. Turns out, I do use it in two ways. First, I use it as a news source. Many of the major tech news (eg @techmeme) and main stream news sites (eg @cbccanada) have Twitter accounts and tweet regularly about their area of interest. I’ll write another post discussing this usage further in the future. The second way I use Twitter, turns out to be a running dialogue to no one in particular (I have 6 followers) about news stories and events that are happening in the world and my life. They aren’t really conversations with anyone, and I’d be perfectly happy if I was the only one who ever read them. Last week, I thought it would be nice to archive my tweets somehow.

So off I went looking for a WordPress plugin which would poll my Twitter stream once a day and post the tweets for the day to this blog. Turns out, there are a ton of Twitter related WordPress plugins available. However, only one advertised the functionality which I was looking for. Lots of them had the ability to show tweets in the sidebar or on a page. I do this already using the javascript right from Twitter, so I didn’t need that. Others advertise the ability to tweet your blog posts or add a tweet facility to the sidebar, but again, I wasn’t looking for something that posted stuff to Twitter. I was looking for something that posted stuff _from_ Twitter.

The only plugin that came close was Alex King’s Twitter Tools plugin. Among other things, this plugin advertised a ‘digest’ facility, which was exactly what I was looking for. Unfortunately, the digest functionality is ‘experimental’ and the plugin is not being actively supported. I futz around with it for a day or two to eliminate some of the issues with the digest (like duplicate posts) and although I fixed a few things (I think) I never really got it to work properly. I’ll be submitting my changes to Alex to see if he wants to use them when I get a moment, but suffice it to say, I gave up on finding a plugin that would do this. Also, I wasn’t wild that the plugin downloads all my tweets and puts them in a special WordPress db, in addition to putting them in a post.

The only thing left to do was to write my own plugin. Over the years, I’ve developed using many languages, but I never had the joy of using PHP beyond some basic modification of existing scripts. This would be the most PHP I’d ever written, although it turns out the Twitter Tools provided much of the formatting of the digest post that I needed. In just a couple of hours, I managed to cobble together a plugin that uses WordPress’ pseudo-cron to fetch tweets from a Twitter account and publish the ones from the previous day. It remembers the last tweet it published so, in theory, their should be no duplicates (I’ve not discounted the possibility of bug induced race conditions).

Long story short, I’ve installed an alpha version on this blog as a live test and to start archiving my own tweets. If anyone actually reads this, you’ll start seeing a daily post of my tweets from the previous day. I still have to write an options page for the plugin so it is useful to people who don’t want to hack the db or php. After that, I’ll see about publishing the plugin in the WordPress plugin repository.