Friday 11 August 2017

count twitter followers using PHP

Hi Members,

If you need to find the number of followers of particular username without logging in to the twitter, then this script will be helpful for you.



Run the script in cli mode and it will give you twitter count.

How to run:
[code]
$ php twitter_follower.php
<follower count>
[/code]

Save the below code as file named twitter_follower.php and  run as instructed above :

[Code]
<?php
$username = "coding-scripting";
$url = "https://twitter.com/$username";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
$pattern = "/followers_count&quot;:(\d+),&quot;/";
if(preg_match($pattern, $data, $count)) {
$followers = $count[1];
print $followers;
}
?>
[Code]

In case of any issue, let me know in comments.

Thanks

No comments:

Post a Comment