Get Twitter Follower Count with PHP

  • Avinash
  • 18
  • Jan 02, 2012
  • Tips & Tricks

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

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.

$url = ""; $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
  $url = "";
  $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

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • Aleks

    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…

    • Avinash

      Aleks, Glad to help, Do not forget to follow us not twitter @ XpertDevelopers also Like us on facebook.

  • Rani

    awesome!! btw, beside the followers number, what else I can get with this method?

    • Avinash

      As per the above code you can just print the $t_profile variable and can see the things you can get..

  • Enrique

    Just was i was looking for, no oauth, nor sdk, nor anything. Direct access and voila. Thanks !!

    • Avinash

      Glad to Help, Don’t forget to Follow us on Twitter, like us on FB

  • Rian Ariona

    Wow, it’s work.. thanks for this code snippet :)

  • Chris

    Finally! I was looking for this, but couldn’t find a good way to get the number. Thanks!

  • Amit Kumar Upadhyay

    Very good article thank you
    but i want a follwoing and tweets count as you show the Followers

    please help me……..

  • Alexandre Parra da Silva

    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!

    • Avinash

      Hello Alexandre,

      I will get that checked and let you know….

      • Alexandre Parra da Silva

        Thank you Avinash!

        • Avinash

          Yes it should work with that too….

          • Alexandre Parra da Silva

            Thanks for your reply!

  • Alvin Konda

    Thanks, Thanks, Thanks. Tried tens of times and now it works fine.

  • MM

    Like it…….

  • ana

    great share. here is a script for tweet url counter:

    • Avinash

      Hi Ana, Your link was using old version of API that’s is is removed from comment