当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Tweepy API.list_subscribers()用法及代码示例


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

API.list_subscribers()

的list_subscribers()方法APITweepy模块中的class类用于获取指定列表的订户。

用法:API.list_subscribers(parameters)

参数:

  • list_id:列表的ID。
  • slug:列表中的子弹。
  • owner_id:列表所有者的ID。
  • owner_screen_name:列表所有者的屏幕名称。
  • count:要获取的订户数量。
  • skip_statuses:布尔值,确定是否返回状态。

返回值:用户类的对象列表



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

# 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 sceen 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)

输出:

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参数仅获取指定数量的订户。

# the slug of the list 
slug = "thought-leaders"
  
# the sceen 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 subscriers fetched:" + str(len(subscribers)))

输出:

The number of subscriers fetched:3



相关用法


注:本文由纯净天空筛选整理自Yash_R大神的英文原创作品 Python – API.list_subscribers() in Tweepy。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。