Skip to content

Instantly share code, notes, and snippets.

@abraham
Created September 26, 2010 21:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save abraham/598349 to your computer and use it in GitHub Desktop.
Save abraham/598349 to your computer and use it in GitHub Desktop.
Quick script to get all of the followers for Twitter users.
<?php
// Require the TwitterOAuth library. http://github.com/abraham/twitteroauth
require_once('twitteroauth/twitteroauth.php');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET);
// Empty array that will be used to store followers.
$profiles = array();
// Get the ids of all followers.
$ids = $connection->get('followers/ids');
// Chunk the ids in to arrays of 100.
$ids_arrays = array_chunk($ids, 100);
// Loop through each array of 100 ids.
foreach($ids_arrays as $implode) {
// Perform a lookup for each chunk of 100 ids.
$results = $connection->get('users/lookup', array('user_id' => implode(',', $implode)));
// Loop through each profile result.
foreach($results as $profile) {
// Use screen_name as key for $profiles array.
$profiles[$profile->screen_name] = $profile;
}
}
// Array of user objects.
var_dump($profiles);
@athakkar
Copy link

What is this CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET parameter how to get ??? i need follower of 'ankit' how to do that?

Thank in advance

@abraham
Copy link
Author

abraham commented Jul 19, 2012

Copy link

ghost commented Aug 27, 2012

I do not know why, but an error like:
Warning: array_chunk() expects parameter 1 to be array, object given in script.php on line 16
Warning: Invalid argument supplied for foreach() in script.php on line 19
array(0) { }

ACCESS_TOKEN, ACCESS_SECRET is the same as OAUTH_TOKEN, OAUTH_SECRET? Right?

@webequation
Copy link

I think It should be like this
$ids_arrays = array_chunk($ids->ids, 100);

you can have look print_r($ids);

@lucianbradford
Copy link

I personally suggest to use WizUgo for twitter automation. And the reason is that I have used this tool and my experience is amazing. It gave me a lot of followers. Now you don’t need to invest time in competing with other twitter accounts as WizUgo has got your back for this, in fact for everything. You don’t need to do anything you can just relax and WizUgo will get you followers, likes and comments. And you can also schedule your tweets too. So easy to use and still got lots of potential. I just love WizUgo for all the services it has.

@NirajVisana
Copy link

i'm getting error

Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in C:\xampp\htdocs\Twi_proj3\TwitterOAuth\TwitterOAuth.php on line 16

i do have http://github.com/abraham/twitteroauth

@NirajVisana
Copy link

i want to get all the followers of users and want to download list in csv or any other formet, so this will help or not?

@VishalMSoni
Copy link

Can this will come to 'rate limit exceeded' error of twitter api or not ?

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