• Skip to content
  • Skip to primary sidebar

WebOmnizz

Header Right

How to display Twitter followers on Website

December 4, 2012 by Jogesh Sharma 1 Comment

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* 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:

1
2
// 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.

Related posts:

  1. Random password generator with php
  2. Base64 encoding format for images
  3. Dynamic select box with php and jquery
  4. Speed Up your website with htaccess caching

Filed Under: Free Stuff Tagged With: API, php

Primary Sidebar

Recent Posts

  • Custom Image Upload in WordPress
  • Top Python Libraries for Data Science in 2017
  • Laravel 5.5 Pagination for Bootstrap 4
  • Implementing Swift Mailer with Codeigniter
  • Building Simple StopWatch with React-Native

WebOmnizz on Google+

Copyright © 2018