Twitter follower count with new Twitter API 1.1

Twitter follower count with new Twitter API 1.1

Twitter API 1.1 is introduced on 11th of June and from that date the old 1.0 search API is discontinued.

There is a lot of tutorials around that uses the old API to get Twitter follower count, but unfortunately, those do not work any more.

One of the main changes to the API with the introduction of the 1.1 API is the implementation of rate limits and most importantly the upgrade to OAuth 2.0 for authentication. There is no more methods that can be called without authentication.

Create a Twitter                   Application

First step is to create a Twitter application and get your consumer’s keys. These are needed to use the oAuth 2.0.

  1. Point your browser and login with your twitter credentials
  2. Create new application
  3. Fill in the form fields and create your app
  4. On the application page, click the “Create my access token”.

You will now have all kind of keys, but for this you will need only Consumer key and Consumer secret

Getting Twitter follower count

So, now we’re ready to start. I will show you how to get Twitter follower count in WordPress, but this code can be easily converted to any other.

Code below is heavily commented. So, basically you copy this to your theme’s functions.php file: