Monday 24 September 2018

PHP function to get the number of twitter followers

The following code snippet will fetch the number of twitter followers of a given twitter username

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
    This function will fetch the number of twitter followers of a twitter id
    It works by fetching an xml page for the user's information
*/
 
function get_followers($twitter_id)
{
    $xml = file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
     
    $s = simplexml_load_string($xml);
     
    $follower_count = $s->followers_count;
     
    return $follower_count;
}
 
/*
    Enter your twitter id here to test the code
*/
$twitter_id = 'linux';
 
echo "$twitter_id has ". get_followers($twitter_id) . ' twitter followers';

0 comments:

Post a Comment