Python – Tweepy 中的状态对象
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
地位
Tweepy 模块中的Status
对象包含有关状态/推文的信息。
以下是 Status 对象中的属性列表:
- created_at : The time the status was posted.
- id : The ID of the status.
- id_str : The ID of the status as a string.
- text : The text of the status.
- entities : The parsed entities of the status such as hashtags, URLs etc.
- source : The source of the status.
- source_url : The URL of the source of the status.
- in_reply_to_status_id : The ID of the status being replied to.
- in_reply_to_status_id_str : The ID of the status being replied to in as a string.
- in_reply_to_user_id : The ID of the user being replied to.
- in_reply_to_user_id_str : The ID of the user being replied to as a string.
- in_reply_to_screen_name : The screen name of the user being replied to
- user : The User object of the poster of the status.
- geo : The geo object of the status.
- coordinates : The coordinates of the status.
- place : The place of the status.
- contributors : The contributors of the status.
- is_quote_status : Indicates whether the status is a quoted status or not.
- retweet_count : The number of retweets of the status.
- favorite_count : The number of likes of the status.
- favorited : Indicates whether the status has been favourited by the authenticated user or not.
- retweeted : Indicates whether the status has been retweeted by the authenticated user or not.
- possibly_sensitive : Indicates whether the status is sensitive or not.
- lang : The language of the status.
示例:考虑以下状态:
使用get_status()
方法获取状态。
# 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 status
id = 1268080321590935553
# fetching the status
status = api.get_status(id)
# printing the information
print("The status was created at : " + str(status.created_at))
print("The id is : " + str(status.id))
print("The id_str is : " + status.id_str)
print("The text is : " + status.text)
print("The entitities are : " + str(status.entities))
print("The source is : " + status.source)
print("The source_url is : " + status.source_url)
print("The in_reply_to_status_id is : " + str(status.in_reply_to_status_id))
print("The in_reply_to_status_id_str is : " + str(status.in_reply_to_status_id_str))
print("The in_reply_to_user_id is : " + str(status.in_reply_to_user_id))
print("The in_reply_to_user_id_str is : " + str(status.in_reply_to_user_id_str))
print("The in_reply_to_screen_name is : " + str(status.in_reply_to_screen_name))
print("The poster's screen name is : " + status.user.screen_name)
print("The geo is : " + str(status.geo))
print("The coordinates are : " + str(status.coordinates))
print("The place is : " + str(status.place))
print("The contributors are : " + str(status.contributors))
print("The is_quote_status is : " + str(status.is_quote_status))
print("The retweet_count is : " + str(status.retweet_count))
print("The favorite_count is : " + str(status.favorite_count))
print("Has the authenticated user favourited the status? : " + str(status.favorited))
print("Has the authenticated user retweeted the status? " + str(status.retweeted))
print("Is the status possibly_sensitive? : " + str(status.possibly_sensitive))
print("The lang is : " + status.lang)
输出 :
The status was created at : 2020-06-03 07:21:23
The id is : 1268080321590935553
The id_str is : 1268080321590935553
The text is : Time really hits differently when you are
??holding a plank for a minute,
??washing your hands for 20 seconds, and… https://t.co/BBg2RIamGy
The entitities are : {‘hashtags’: [], ‘symbols’: [], ‘user_mentions’: [], ‘urls’: [{‘url’: ‘https://t.co/BBg2RIamGy’, ‘expanded_url’: ‘https://twitter.com/i/web/status/1268080321590935553’, ‘display_url’: ‘twitter.com/i/web/status/1…’, ‘indices’: [116, 139]}]}
The source is : Twitter Web App
The source_url is : https://mobile.twitter.com
The in_reply_to_status_id is : None
The in_reply_to_status_id_str is : None
The in_reply_to_user_id is : None
The in_reply_to_user_id_str is : None
The in_reply_to_screen_name is : None
The poster’s screen name is : geeksforgeeks
The geo is : None
The coordinates are : None
The place is : None
The contributors are : None
The is_quote_status is : False
The retweet_count is : 2
The favorite_count is : 31
Has the authenticated user favourited the status? : True
Has the authenticated user retweeted the status? False
Is the status possibly_sensitive? : False
The lang is : en
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。