Python – Tweepy 中的列表对象
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。要做的第一件事是从 Twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
列表
Tweepy 模块中的List对象包含有关列表的信息。
以下是 List 对象中的属性列表:
- id : The ID of the list.
- id_str : The ID of the list as a string.
- name : The name of the list.
- uri : The URI of the list.
- subscriber_count : The number of subscribers of the list.
- member_count : The number of members of the list.
- mode : The mode of the list.
- slug : The slug of the list.
- full_name : The full name of the list.
- created_at : The time when the list was created at.
- following : Indicates whether the authenticated user is following the list or not.
- user : The user object of the owner of the list.
示例:使用 get_list() 方法获取列表。
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 ID of the list
list_id = 4343
# fetching the list
list = api.get_list(list_id = list_id)
# printing the information
print("The id is : " + str(list.id))
print("The id_str is : " + list.id_str)
print("The name is : " + list.name)
print("The uri is : " + list.uri)
print("The subscriber_count is : " + str(list.subscriber_count))
print("The member_count is : " + str(list.member_count))
print("The mode is : " + list.mode)
print("The slug is : " + list.slug)
print("The full_name is : " + list.full_name)
print("The list was created on : " + str(list.created_at))
print("Is the authenticated user following the list? : " + str(list.following))
print("The screen name of the owner of the list is : " + list.user.screen_name)
输出 :
The id is : 4343
The id_str is : 4343
The name is : Thought Leaders
The uri is : /kitson/lists/thought-leaders
The subscriber_count is : 4066
The member_count is : 382
The mode is : public
The slug is : thought-leaders
The full_name is : @kitson/thought-leaders
The list was created on : 2009-10-15 23:03:44
Is the authenticated user following the list? : False
The screen name of the owner of the list is : kitson