Skip to content

Instantly share code, notes, and snippets.

@gimesi
Last active January 16, 2016 12:56
Show Gist options
  • Save gimesi/6534670 to your computer and use it in GitHub Desktop.
Save gimesi/6534670 to your computer and use it in GitHub Desktop.
Show the number of followers of a Twitter account.
<?php
/*
* Requires the "Twitter API" wrapper by James Mallison
* to be found at https://github.com/J7mbo/twitter-api-php
*
* The way how to get a follower count was posted by Amal Murali
* on http://stackoverflow.com/questions/17409227/follower-count-number-in-twitter
*/
require_once('TwitterAPIExchange.php'); // adjust server path accordingly
// GET YOUR TOKENS AND KEYS at https://dev.twitter.com/apps/
$settings = array(
'oauth_access_token' => "YOUR_ACCESS_TOKEN", // enter your data here
'oauth_access_token_secret' => "YOUR_ACCESS_TOKEN_SECRET", // enter your data here
'consumer_key' => "YOUR_CONSUMER_KEY", // enter your data here
'consumer_secret' => "YOUR_CONSUMER_KEY_SECRET" // enter your data here
);
$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=YOURNAME'; // enter your twitter name without the "@" here
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$follow_count=$twitter->setGetfield($getfield)
->buildOauth($ta_url, $requestMethod)
->performRequest();
$data = json_decode($follow_count, true);
$followers_count = $data[0]['user']['followers_count'];
?>
<?php echo $followers_count; ?>
@vignestion
Copy link

but it returns me error like this

Fatal error: Uncaught exception 'Exception' with message 'SSL certificate problem: unable to get local issuer certificate' in C:\wamp\www\hy\TwitterAPIExchange.php on line 305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment