Hacking the Twitter Ultimate-WordPress Plugin

Hacking the Twitter Ultimate-WordPress Plugin

QUICKFIX: replace twitter.js with the contents of this file in the Twitter Ultimate Plugin via the editor in WordPress. Also upload this file‘s contents to a new file called twitter-proxy.php in the directory: wp-content/plugins/twitter_ultimate/ Fill in the details of this last file with the keys from your new app which you set up here.

(This file is my original file with the lines I have changed annotated if you get stuck)

A friend on mine recently had an issue with a Twitter API call since Twitter retired their older API 1 and have moved everything up to 1.1. (In fact it was a WordPress plugin called Twitter Ultimate which makes nice jQuery calls to update the UI should someone have posted something new). I managed to get a temporary fix in place that allows the calls to connect, as shown below, with the help of a great blog post which pretty much solved my solution to this plugin problem by authenticating using oAuth in php. My javascript would now call this authentication (via jQuery.getJSON) before making the actual request for the tweets (search/tweets API call).

Firstly you have to create an app on the Twitter developer site for the authentication – https://dev.twitter.com/apps/new which is quite a quick 2 minute process. Once you have done this you will need to take note of 4 things:

  • Consumer key
  • Consumer secret
  • Access token
  • Access token secret

You need to make sure you don’t call this too often as there is a limit to the number of calls you can make as defined in the documentation. Currently Twitter limit to once every 5 seconds (on average) and if you go over it will block you until 15 minutes from your first call is up. It is actually 180 calls in 15 minutes. For the purposes of this plugin I have edited it to be once every 10 seconds instead of the default 5 seconds – but remember many people accessing the same page count as new connections. You can make a call to rate_limit_status which will tell you (in Unix time) when the limit will be reset for your application.

I had to add a twitter-proxy.php file to the plugin directory firstly and editing the constants at the top of the file of the new app that I created above.

Then a little hacking of the twitter.js file allowed me to call the proxy authentication code first. (Changes in comments)

Now the page works just as it did before – but sometimes I get a rate limit exceeded error (which I have to use a debugger for) which could be handled more nicely.

I also noticed there seemed to be a glitch with new tweets that came in not having their timestamps updated further down the line. Answers on a postcard please!

Please do let me know if this is useful or it doesn’t work: via my Twitter.

Comments are closed.