Fixing Twitter Feeds

By next week (March 2013) Twitter will be switching off version 1 of its API forcing everyone to use version 1.1. For most the only difference you need to know between these two is that v1.1 requires authentication before you can access any goodies.

And it's this authentication that means any script, plugin or website that makes use of version 1 of the API will need to change, and change quickly, to the newer API. If this isn't done then best case is you won't see any new tweets on your website. Worst case is it could break your whole website if it's heavily dependent on Twitter.

What to do?

If you use a third party plugin then simply ensure it's up to date, and that the plugin is still being developed. It might be the latest version but that could have been released years ago and the plugin isn't actually being maintained anymore.

If it's not a plugin and it doesn't already use v1.1 of the API you need to either update the code yourself if you're proficient or get a developer to do it for you. If it's not using OAuth anywhere in the code then chances are it needs updating.

We've had to do this for many of our clients Twitter feeds as we've always used a custom script to get a person or companies latest tweets.

If it wasn't for the fact it was about to break we'd have happily left this as it was as the code had been refined over time to be pretty handy. It included things like a cache and also checked Twitter rate limits. I'm sure there's more that could have been done to refine it but it did the job.

Today

From midday our code now looks like this (we've not copied some of the child functions that haven't changed):

This time we've used a library to help deal with the complexities of OAuth and save us some time. Where possible we like to use our own code but we're a little limited for time so we just needed a workable solution and CodeBird was one of the most lightweight libraries we came across.

This implementation also requires creating an application at dev.twitter.com to generate consumer keys and access tokens.

Much of the code works as it did before; the only differences are the change in how we access the information and the removal of us checking the rate limit.

Limiting the rate limit

When we came to changing this part of the script we found that there was a limit on checking the rate limit. That was a bit of a head scratcher. And as we checked the rate limit more than we actually got new tweets in the previous script we've just removed this.

It's somewhat helpful that v1.1 provides a higher limit than v1 so hopefully we won't hit the limit all that often anyway, especially given we only check once per hour, per domain.

Test, Test, Test

If you do look at our code above and want to use it feel free but there is a disclaimer…

We've only had this running on one site for a few hours. It's working great so far but if something goes wrong for you we're not responsible

Kean Richmond

The creative mind of Bronco, Kean works hard to ensure that all our websites, including this site, not only look great for the human visitor, but most importantly they are built to be search engine friendly.

Making your inbox more interesting

Looking to keep up to date, or find out those things we can’t mention on the blog? Then sign up to our semi-regular newsletter. Don’t worry, we won’t spam you.

Email Address

Comments are closed.

Get in Touch

Things are better when they’re made simpler. That’s why the David Naylor blog is now just that; a blog. No sales pages, no contact form - just interesting* info about SEO.

If you’d like to find out more about the Digital Marketing services we do provide then head over to Bronco (our main company website) to get in touch.