In previous post I have explined about getting the Facebook page details using Graph API and PHP. Now this post is about to get the Twitter Follower Count using PHP.
For this method what you will need is just and User Name of the Twitter Account. For Example Expert Developer’s Twitter Account is XpertDevelopers.
How it Works
Like Facebook Graph API, you just make one call to twitter URL using you twitter account name. So our twitter account is XpertDevelopers, then that URL will be http://twitter.com/users/show/XpertDevelopers
You will need to get the content of this URL and have to parse the content to get the Follower Count. Let’s see how to get this done with example.
[cc lang=”php”]
$url = “http://twitter.com/users/show/XpertDevelopers”;
$response = file_get_contents ( $url );
$t_profile = new SimpleXMLElement ( $response );
$count = $t_profile->followers_count;
echo “Expert Developer Twitter Followers : “.$count;
// Output
Expert Developer Twitter Followers : 73
[/cc]
No cache, no fancy javascript, no overcomplicated stuff, no CSS for styling, no nothing.
Just a simpleXMLElement.
You sir, are my hero… NONE of these other crap tutorials around have actually worked, or it has allways had a bug in them, or just a general shitty support, or depends on a SHITLOAD of libraries. This… So simple, so clean… So just… Exactly what I was looking for…
Aleks, Glad to help, Do not forget to follow us not twitter @ XpertDevelopers also Like us on facebook.
awesome!! btw, beside the followers number, what else I can get with this method?
As per the above code you can just print the $t_profile variable and can see the things you can get..
Just was i was looking for, no oauth, nor sdk, nor anything. Direct access and voila. Thanks !!
Glad to Help, Don’t forget to Follow us on Twitter, like us on FB
Wow, it’s work.. thanks for this code snippet :)
Finally! I was looking for this, but couldn’t find a good way to get the number. Thanks!
Very good article thank you
but i want a follwoing and tweets count as you show the Followers
please help me……..
Hello Avinash,
This method is very good for its simplicity, as others have stated.
Do you know if it will still be available after the API v1.0 deprecation scheduled for coming March?
Thank you!
Hello Alexandre,
I will get that checked and let you know….
Thank you Avinash!
Yes it should work with that too….
Thanks for your reply!
Thanks, Thanks, Thanks. Tried tens of times and now it works fine.
Like it…….
great share. here is a script for tweet url counter:
Hi Ana, Your link was using old version of API that’s why it is removed from comment