I am trying to get my twitter follower count to show on my website. I have set up the twitter API to receive the follower count, and that has been tested using echo and that is working perfectly.
The problem is I can't work out how to pass that value into the html.
This is the code that gets the twitter count:
<?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('twitterapi/TwitterAPIExchange.php'); // adjust server path accordingly
// GET YOUR TOKENS AND KEYS at https://dev.twitter.com/apps/
$settings = array(
'oauth_access_token' => "SECRET", // enter your data here
'oauth_access_token_secret' => "SECRET", // enter your data here
'consumer_key' => "SECRET", // enter your data here
'consumer_secret' => "SECRET" // enter your data here
);
$ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=SECRET'; // 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'];
?>
And this is the code to pass the $followers_count variable into the html.
It's a span tag with the id "twit-follow-count".
<script type="text/javascript">
$( document ).ready(function() {
$('#twit-follow-count').html($followers_count);
});
</script>
Any help would be greatly appreciated!