Tuesday 10 June 2014

How To Display Twitter Followers Count In PHP


Twitter is one of the most used social networking websites on the internet. Twitter API allows you to retrieve info for specific user. All you need to do is to enter the handler of the user. You can easily retrieve a specific Twitter user’s followers count with a small snippet:

<php
function twitter_user_info($screen_name){
 
    $data = file_get_contents("https://api.twitter.com/1.1/users/lookup.json?screen_name=" . $screen_name);
    $data = json_decode($data, true);
    //echo $data;
    return $data[0];
}
 
$twitter = twitter_user_info("srinuchilukuri");
echo "Followers count: " . $twitter['followers_count'];

>

Just replace "srinuchilukuri" in the above code with your Twitter handler to retrieve your followers. Just like this example, you can also retrieve possibly every public Twitter user info with this API.

You can retrieve every Twitter info with following snippet:
<php
function twitter_user_info($screen_name){
 
    $data = file_get_contents("https://api.twitter.com/1.1/users/lookup.json?screen_name=" . $screen_name);
    $data = json_decode($data, true);
    //echo $data;
    return $data[0];
}
 
$twitter = twitter_user_info("srinuchilukuri");
print_r($twitter);

>
The above code will give you following output:
Array
(
    [id] =1336470266
    [id_str] =1336470266
    [name] =Srinu Chilukuri
    [screen_name] =srinuchilukuri
    [location] =Hyderabad
    [url] =http://knowledgecornor.blogspot.in
    [description] =Software Engineer
    [protected] = 
    [followers_count] =11
    [friends_count] = 83
    [listed_count] = 0
    [created_at] =Mon Apr 08 12:00:21 +0000 2013
    [favourites_count] = 3
    [utc_offset] = 19800
    [time_zone] = Chennai
    [geo_enabled] = 
    [verified] = 
    [statuses_count] = 78
    [lang] = en
    
    )

No comments:

Post a Comment