0

I have been looking around the web today to see how I could get a list of followers from twitter.

Apart of the code is -

$tweet->get('followers/ids', array('screen_name' => 'YOUR-SCREEN-NAME-USER', 'cursor' => 9999999999));

My Question is, How do I create a loop to display "Screen_name" of all my followers

4
Contributors
9
Replies
43
Views
3 Years
Discussion Span
Last Post by diafol
0

Here is the code I have picked up off the web...

I have created my twitter app and I am trying to get a full list of all my followers.

<?php
$consumerKey = '#';
$consumerSecret = '#';
$oAuthToken = '#';
$oAuthSecret = '#';

# API OAuth
require_once('./twitter/twitteroauth.php');

$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);

$tweet->get('followers/ids', array('screen_name' => 'twitter_name_here'));

    }
0

Maybe...

$ids = $tweet->get('followers/ids', array('screen_name' => 'twitter_name_here'));

print_r(json_decode($ids,true));
0

Hi @Diafol -

When I use what you suggested I get the following error message -

json_decode() expects parameter 1 to be string on line 16

Here is Line 15 & 16

$ids = $tweet->get('followers/ids', array('screen_name' => 'twiiter_name_here'));
print_r(json_decode($ids,true));
0

just another maybe :). I am borrowing Diafol's last line of code.

$followers = json_decode($ids, true);

foreach($followers as $follower){

    echo $follower .'<br/>';

    }
0

Thanks Gents but im still getting this error

Warning: json_decode() expects parameter 1 to be string, object given in line 16

Warning: json_decode() expects parameter 1 to be string, object given in line 18

Warning: Invalid argument supplied for foreach() in line 19

here are lines 15,16,18 & 19

$ids = $tweet->get('followers/ids', array('screen_name' => 'twitter_name_here'));
print_r(json_decode($ids,true));

$followers = json_decode($ids, true);
foreach($followers as $follower){
    echo $follower .'<br/>';
    }
0

It gives me an array of ids

stdClass Object ( [ids] => Array ( [0] => 329887653 [1] => 564466886 [2] => 1087014949 [3] =>

0

OK - I thought that it would return a json structure, not the actual std object. In this case...

$array = $ids->ids;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.