Skip to content

Instantly share code, notes, and snippets.

@abraham
Created September 26, 2010 21:53
Show Gist options
  • 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);
@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