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

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

Python – Tweepy 中的 API.show_list_subscriber()

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

API.show_list_subscriber()

Tweepy 模块中API类的show_list_subscriber()方法用于检查用户是否是指定列表的订阅者。

示例 1:当用户订阅列表时。

# 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 ID of the list
list_id = 4343
  
# screen name of the user to be checked
screen_name = "LiptakCarl"
  
# checking if the user is subscribed to the list
api.show_list_subscriber(list_id = list_id, screen_name = screen_name)
  
# if no exception is raised then the user is subscribed to the list
print("The user " + screen_name + " is subscribed to the list " +
      api.get_list(list_id = list_id).name)

输出 :

The user LiptakCarl is subscribed to the list Thought Leaders

示例 2:当用户未订阅列表时,将引发异常。

# the ID of the list
list_id = 4343
  
# screen name of the user to be checked
screen_name = "geeksforgeeks"
  
# checking if the user is subscribed to the list
api.show_list_subscriber(list_id = list_id, screen_name = screen_name)
  
# if no exception is raised then the user is subscribed to the list
print("The user " + screen_name + " is subscribed to the list " +
      api.get_list(list_id = list_id).name)

输出 :

raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 109, 'message': 'The specified user is not a subscriber of this list.'}]