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

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'));

    }
Member Avatar for diafol

Maybe...

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

print_r(json_decode($ids,true));

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));

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

$followers = json_decode($ids, true);

foreach($followers as $follower){

    echo $follower .'<br/>';

    }

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/>';
    }
Member Avatar for diafol

What does this

print_r($ids);

give you?

It gives me an array of ids

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

Member Avatar for diafol

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

$array = $ids->ids;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.