Python – API.list_subscribers() in Tweepy
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.list_subscribers()
The list_subscribers() method of the API class in Tweepy module is used fetch the subscribers of a specified list.
Syntax : API.list_subscribers(parameters)
Parameters :
- list_id : ID of the list.
- slug : slug of the list.
- owner_id : ID of the owner of the list.
- owner_screen_name : screen name of the owner of the list.
- count : number of subscribers to be fetched.
- skip_statuses : boolean determining whether to return statuses or not.
Returns : a list of objects of class User
Example 1 : Printing the screen names of the 20 latest subscribers.
Python3
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)
slug = "thought-leaders"
owner_screen_name = "kitson"
subscribers = api.list_subscribers(slug = slug,
owner_screen_name = owner_screen_name)
for subscriber in subscribers:
print (subscriber.screen_name)
|
Output :
Saddds305
rachellelive
hazemkhattab8
constantine_fry
rockivy4
edwinealmonte
satishvkvn
puppies221122
55_CancriF
jameschancepro1
LiptakCarl
TheMarkShaw
mitch_plzzzz
ahrimango
nidhishetty
jmpena33
TuttleRose
rgolwalkar
BillRingle
Nellie_I_Am
Example 2 : Using the count parameter to fetch only a specified number of subscribers.
Python3
slug = "thought-leaders"
owner_screen_name = "kitson"
count = 3
subscribers = api.list_subscribers(slug = slug,
owner_screen_name = owner_screen_name,
count = count)
print ( "The number of subscribers fetched : " + str ( len (subscribers)))
|
Output :
The number of subscribers fetched : 3
Last Updated :
21 Dec, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...