Python Tweepy – Getting the number of followers of a user
Last Updated :
18 Jun, 2020
In this article we will see how we can get the number of followers of a user. The followers_count attribute provides us with an integer donating the number of followers the user account has.
Identifying the number of followers in the GUI :
In the above mentioned profile the number of followers are : 17.8K (17, 800+)
In order to get the number of followers we have to do the following :
- Identify the user ID or the screen name of the profile.
- Get the User object of the profile using the
get_user()
method with the user ID or the screen name.
- From this object, fetch the followers_count attribute present in it.
Example 1: Consider the following profile :
We will use the user ID to fetch the user. The user ID of the above mentioned profile is 57741058.
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
id = 57741058
user = api.get_user( id )
followers_count = user.followers_count
print ( "The number of followers of the user are : " + str (followers_count))
|
Output :
The number of followers of the user are : 17814
Example 2: Consider the following profile :
We will use the screen name to fetch the user. The screen name of the above mentioned profile is PracticeGfG.
screen_name = "PracticeGfG"
user = api.get_user(screen_name)
followers_count = user.followers_count
print ( "The number of followers of the user are : " + str (followers_count))
|
Output :
The number of followers of the user are : 2204
Share your thoughts in the comments
Please Login to comment...