📌  相关文章
📜  Python – Tweepy 中的 API.list_subscribers()

📅  最后修改于: 2022-05-13 01:55:14.552000             🧑  作者: Mango

Python – Tweepy 中的 API.list_subscribers()

Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。

API.list_subscribers()

Tweepy 模块中 API 类的list_subscribers()方法用于获取指定列表的订阅者。

示例 1:打印 20 个最新订阅者的屏幕名称。

Python3
# import the module
import tweepy
 
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
 
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
 
# set access to user's access key and access secret
auth.set_access_token(access_token, access_token_secret)
 
# calling the api
api = tweepy.API(auth)
 
# the slug of the list
slug = "thought-leaders"
 
# the screen name of the owner of the list
owner_screen_name = "kitson"
 
# fetching the subscribers
subscribers = api.list_subscribers(slug = slug,
                                   owner_screen_name = owner_screen_name)
 
# printing the screen names of the subscribers
for subscriber in subscribers:
    print(subscriber.screen_name)


Python3
# the slug of the list
slug = "thought-leaders"
 
# the screen name of the owner of the list
owner_screen_name = "kitson"
 
# number of subscribers to be fetched
count = 3
 
# fetching the subscribers
subscribers = api.list_subscribers(slug = slug,
                                   owner_screen_name = owner_screen_name,
                                   count = count)
 
print("The number of subscribers fetched : " + str(len(subscribers)))


输出 :

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

示例 2:使用 count 参数仅获取指定数量的订阅者。

Python3

# the slug of the list
slug = "thought-leaders"
 
# the screen name of the owner of the list
owner_screen_name = "kitson"
 
# number of subscribers to be fetched
count = 3
 
# fetching the subscribers
subscribers = api.list_subscribers(slug = slug,
                                   owner_screen_name = owner_screen_name,
                                   count = count)
 
print("The number of subscribers fetched : " + str(len(subscribers)))

输出 :

The number of subscribers fetched : 3