Twitter’s new API 1.1 has been live for a couple of months now and that brings with it a whole new set of requirements for using the Twitter API. From March 2013, everyone displaying tweets must comply with the new terms and update their websites code to be compliant with the new requirements, which includes changes to the way you authenticate.

This basically means you won’t be able to use Javascript to load in tweets for your website directly from Twitter, as all requests must be authenticated.

This is a major problem for the vast majority of websites that are currently using Twitter and one we needed to work around – so we built a PHP class (GitHub), and a WordPress plugin (GitHub), that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your WordPress themes, or PHP applications. We built the class and plugin on top of Abraham Williams’s Twitter OAuth class which makes the OAuth stuff really easy.

You can get the plugin from the WordPress plugin directory: oAuth Twitter Feed for Developers.

The plugin implements caching for (by default) 1 hour too, to stop you hitting the API limits which could occur with the new authenticated-only request requirements and protects you from Twitter outages. You can change this yourself in the source code.

It’s definitely for developers though – you only get an array out of it that contains Twitter tweet objects (You’ll find more about them on the Twitter API documentation). You’ll still need to style the output and make it comply with the new display requirements.

The plugin provides a getTweets() function that you can call in your theme files. This returns an array you can then loop over and do whatever you want with it.

$tweets = getTweets(); var_dump($tweets); foreach($tweets as $tweet){ var_dump($tweet); }

You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you’d request getTweets(1).

This is an early release of the class and plugin, both could offer a lot more functionality. If you want to get involved, fork the code on GitHub and send us a Pull Request!