DEV Community

Ichi
Ichi

Posted on • Edited on

2 4

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

Simply

  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.

Thanks.
My Website
Twitter@tomox0115

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay