Question

I'm using a PHP wrapper for my Twitter API calls which is found here.

I'm trying to get a follower count for my account and I am using

$url = 'https://api.twitter.com/1.1/users/show.json';
$getfield = '?screen_name=symphaticidiot';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
                ->buildOauth($url, $requestMethod)
                ->performRequest();

var_dump(json_decode($response));

This works and does display the information. How do I filter it so it will only display follower_count instead of

object(stdClass)#2 (43) { ["id"]=> int(391356688) ["id_str"]=> string(9) "391356688"                                         ["name"]=> string(8) "It's Dom" ["screen_name"]=> string(14) "symphaticidiot" ["location"]=> string(13) "Hull, England" ["description"]=> string(110) "Specialised Generalist, #webguy, #poet, #IT Techie and the guy who has @amb_freeman as his amazing girlfriend." ["url"]=> string(22) "http://t.co/YSoqD2K0NZ" ["entities"]=> object(stdClass)#3 (2) { ["url"]=> object(stdClass)#4 (1) .....
Was it helpful?

Solution

I got it working using the following code

$url = 'https://api.twitter.com/1.1/users/show.json';
$getfield = '?screen_name=symphaticidiot';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
                    ->buildOauth($url, $requestMethod)
                    ->performRequest();

$json_output = json_decode($response);

$followers = $json_output->followers_count
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top