How to display Twitter followers on Website

If we talking about Social Network then Google+, Facebook and Twitter are the biggest giant in this field. Let’s talking about Twitter. One of the best way to convey your message to your friends and followers. Twitter also help to increase your traffic on your website or blog. If you notice in most of the websites; people likes to display twitter followers on websites. That also impact to the visitor.

What have to do to show Twitter followers on website?

No need to worry if you are not familiar with the programming, just copy the codes and paste it into your PHP file.

/*
* Get Twitter Follower
* =====================
* @param String Username
* @return String Followers
*/

function getTwitterFollower($user='webomnizz'){

    $apiurl = "http://api.twitter.com/1/users/show.json?screen_name={$user}";

    // CURL Request
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $apiurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    curl_close($ch);

    // Decode JSON data,
    // Convert into array
    $tw_data = json_decode($data, true);

    return $tw_data['followers_count'];
}

 

Now just simply call the given function getTwitterFollower() and pass your Twitter account name into this function, something like:

// call the function
echo getTwitterFollower('Your_Twitter_Account_name');

 

I have used the CURL library with PHP, to fetch the twitter followers. Take a look on the twitter developers section. I just pass the account name to the URL and fetch the data into JSON format. Simply decode the JSON data with the help of json_decode().

Hope you all enjoy this post, if you have some suggestion, then please get in touch through comment section.

Posted by Jogesh Sharma

Jogesh Sharma is a web developer and blogger who loves all the things design and the technology, He love all the things having to do with PHP, WordPress, Joomla, Magento, Durpal, Codeigniter, jQuery, HTML5 etc. He is the author of this blog.