Python Tweepy – 获取用户创建时间
在本文中,我们将了解如何获取用户创建 Twitter 帐户的时间和日期。 created_at 属性为我们提供了一个日期时间对象,表示创建用户帐户的确切时间。
识别在 GUI 中创建用户的日期:
在上述配置文件中,用户创建于 2009 年 7 月。
In order to get the date and time when the user was created, we have to do the following :
- Identify the user ID or the screen name of the profile.
- Get the User object of the profile using the
get_user()
method with the user ID or the screen name. - From this object, fetch the created_at attribute present in it.
示例 1:考虑以下配置文件:
我们将使用用户 ID 来获取用户。上述配置文件的用户 ID 是 57741058。
# 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 user
id = 57741058
# fetching the user
user = api.get_user(id)
# fetching the create_at attribute
created_at = user.created_at
print("The user was created on : " + str(created_at))
输出 :
The user was created on : 2009-07-17 20:02:09
示例 2:考虑以下配置文件:
我们将使用屏幕名称来获取用户。上述个人资料的网名是 PracticeGfG。
# the screen name of the user
screen_name = "PracticeGfG"
# fetching the user
user = api.get_user(screen_name)
# fetching the create_at attribute
created_at = user.created_at
print("The user was created on : " + str(created_at))
输出 :
The user was created on : 2016-01-23 12:03:47
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。