DEV Community


Posted on • Updated on

Get a list of follow/follower infomation of Twitter account in 4 lines

Today, I will try to get the follower list in 4 lines.
However, I only use the usual Twittroauth, but if you do not have abraham / twitteroauth, please do so from Composer.

composer require abraham/twitteroauth
Enter fullscreen mode Exit fullscreen mode

The API limit is 5000 per user. If you want to get more, you can loop with "for". Note that oauth_token and oauth_token_secret are not required and can be accessed.
For details ↓
TwitterDev Official Reference

Get list of follower

require 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
$connection = new TwitterOAuth("APIKey", "APISecret");
$followers = $connection->get("followers/list",array('cursor' => '-1', 'screen_name' => 'screen_name','count'=>'100'));
Enter fullscreen mode Exit fullscreen mode


  1. Auto loading
  2. Namespace import
  3. Credential settings & instantiation
  4. Get

that's all.
Information is returned as a class object

Get list of Follow

Just change followers/list on the 4th line to friends/list.

My Website

Top comments (0)