Since the deactivation of the old API, retrieving a public twitter feed from the API isn’t as simple as it used to be. All requests must now be authenticated, which requires creating an app with twitter and a signing your requests.

A while ago I wrote a post detailing how to create a simple twitter cache using PHP to avoid your Twitter feed disappearing when the API gets overloaded (which seems to happen very frequently). After reading through Twitter’s forums trying to figure out the easiest way to authenticate my requests, it turns out that there’s a very simple way to get your twitter feed up and running again without having to use a bunch of authentication libraries.

First, you’ll need to register an app with twitter. Sign into using your Twitter login details, and create an app. You can call it whatever you want, and it only requires read-only access. Once this it done, note down your Consumer Key and Consumer Secret.

The next step is courtesy of Kieran Metcalfe over from the Twitter Forum. He documented this awesome process of obtaining a bearer token, which will allow us to retrieve the feed without having to use an oauth library.

Run this snippet once using your key/secret combo to obtain the bearer token, and note it down.

You can then use the following modified version of my twitter feed cache, replacing the bearer token with your own. Save this as a file somewhere in your project directory; this is the file you’ll call to retrieve the twitter feed. You can change the interval if you want the file to be cached for longer/shorter period of time.

Note: you’ll need to create a cache folder in the same directory as the script, and a twitter-cache file inside that in order to avoid first-run errors. The script should create the file automatically if it doesn’t exist (albeit returning a warning), but you’ll need to make sure the folder exists first by creating it manually.

And now you’re free to do whatever you like with the feed. For example, if you want to insert it into your page with some jQuery, you can use the following code:

If you’ve got any questions or problems, please don’t hesitate to let me know in the comments.

If this post has helped you out, feel free to consider throwing a small donation my way.