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:
$ php twitter_follower.php
<follower count>

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

$username = "coding-scripting";
$url = "$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);
$pattern = "/followers_count&quot;:(\d+),&quot;/";
if(preg_match($pattern, $data, $count)) {
$followers = $count[1];
print $followers;

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


No comments:

Post a Comment