Home » Home Server » Get Twitter followers count using PHP

Get Twitter followers count using PHP

written by Anand August 16, 2012

Recently, I wrote a post on how to get Facebook like count using PHP. Continuing along the same lines, in this post, I will explain how to get Twitter followers count using a simple PHP script. The number can be stored in cache or a database and displayed as simple text or combined with other numbers to display a total followers/subscribers count. It also slightly improves page load speeds. For this reason you may find that many of the blogs just provide a link to their Twitter page. I personally like to provide a like button on the blog, which makes it convenient for the visitors to follow with just a couple of clicks. So without further delay, here it goes.

Get Twitter Followers Count

Twitter Follow Button

PHP code to get Twitter Followers Count

The PHP script to get Twitter followers count is pretty simple and straightforward:

https://www.smarthomebeginner.com/wp-admin/post.php?post=3196&action=edit&message=1#suggestion-4
$twurl = "http://twitter.com/users/show/htpcBeginner";
$response = file_get_contents ( $twurl );
$t_profile = new SimpleXMLElement ( $response );
$tcount = $t_profile->followers_count;

$twurl is the variable to hold your Twitter page. Replace htpcBeginner with your account name. You can get it from your Twitter page:

Twitter Username

Twitter Username

After you get Twitter followers count, you can display it as simple text using the following PHP code:

echo $tcount.' follow htpcbeginner.com';

This will output 7 follow htpcbeginner.com.

You can even get counts of your Facebook likes and Feedburner subscribers and add them all together and display a combined followers count like this:

Combined Followers Subscribers Count

Combined Followers Subscribers Count

Twitter Followers Count History

Although you may be able to get Twitter followers count history and more by other means, I like to record the data in a format I like. I currently get Facebook like count, Twitter followers count, FeedBurner subscribers count, and Alexa site rank and record them in a MySQL database daily to see the growth of my blog. If you make any changes / improvements to your blog then you have the data to see what impact it had on your followers count. In a separate post, I will explain how to accomplish this.

Meanwhile, get Twitter followers count using the above script, get creative, and find innovative ways to use the count. Please do not forget to share your idea with us in the comments sections.

IPVanish VPN Exclusive 20% Off - only $5.19/month:
VPN Guides
Windows, Android, Ubuntu
Kodi OpenVPN
OSMC on RPi
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ Money back guarantee - Sign Up Now

Related Articles