I’m trying to read the follower list using Tweepy v2.
import tweepy
# Your credentials
client = tweepy.Client(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret
)
The above code is returning correct client information which I can verify with:
# Get your own user ID
me = client.get_me()
my_id = me.data.id
However, I am not able to get the follower list, I tried following multiple approaches from documentation:
# Get followers
followers = []
for response in tweepy.Paginator(client.get_users_followers, my_id, max_results=1000):
followers.extend(response.data)
I get 401.
---------------------------------------------------------------------------
Unauthorized Traceback (most recent call last)
<ipython-input-45-2fa8b522e9f3> in <cell line: 3>()
1 # Get followers
2 followers = []
----> 3 for response in tweepy.Paginator(client.get_users_followers, my_id, max_results=1000):
4 followers.extend(response.data)
3 frames
/usr/local/lib/python3.10/dist-packages/tweepy/client.py in request(self, method, route, params, json, user_auth)
96 raise BadRequest(response)
97 if response.status_code == 401:
---> 98 raise Unauthorized(response)
99 if response.status_code == 403:
100 raise Forbidden(response)
Unauthorized: 401 Unauthorized
Unauthorized
https://docs.tweepy.org/en/stable/client.html#tweepy.Client.get_users_followers