Php Twitter Followers Count
The following PHP Twitter Followers Count script is using the new v1.1 Twitter API.
Recently, Twitter have changed their API and v1.0 is obselete. The new API requires OAuth. I’ll explain how to get your twitter followers count using PHP.
First, you’ll need to get yourself a twitter dev account, if you haven’t done so yet.
Go here and register your app free.
Download the TwitterAPIExchange library files created by J7mbo into your application.
git clone https://github.com/J7mbo/twitter-api-php
I recommend the git method as you can git pull later to recieve updated.
Get Followers Count
Insert your OATH and Consumer Access-Token & Access-Token secret the the following code. Also, change the $getfield screen name to yours.
Now combine everything to make it work
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN",
'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=replace_me;
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$data = json_decode($follow_count, true);
I’ve placed the entire twitter-api-php folder inside my project. you can extract the files also, but make sure to require_once() from the correct path.
if you’ve placed it inside the folder, or
require_once(‘TwitterAPIExchange.php’); if you extracted the files to the same folder as your script.
This article was based on the work of Jimbo and Meenakshi Sundaram R