Python – Tweepy 中的用户对象
Twitter是一个流行的社交网络,用户在其中分享称为推文的消息。 Twitter 允许我们使用 Twitter API 或Tweepy挖掘任何用户的数据。数据将是从用户那里提取的推文。首先要做的是从 twitter 开发人员那里轻松获得每个用户可用的消费者密钥、消费者密钥、访问密钥和访问密钥。这些密钥将帮助 API 进行身份验证。
用户
Tweepy 模块中的User
对象包含有关用户的信息。
以下是 User 对象中的属性列表:
- id : The ID of the user.
- id_str : The ID of the user as a string.
- name : The name of the user.
- screen_name : The screen name of the user
- location : The location of the user.
- profile_location : The location of the the profile.
- description : The description of the user account.
- url : The URL of the user account.
- entities : A dictionary containing URLs.
- protected : Indicates if the user profile is protected or not.
- followers_count : The number of followers the account has.
- friends_count : The number of friends the account has.
- listed_count : The number of public lists the account has been added to.
- created_at : The time at which the account was created.
- favourites_count : The number of statuses the account has favourited.
- utc_offset : The UTC offset of the profile.
- geo_enabled : Indicates whether the account is geo enabled or not.
- verified : Indicates whether the user is verified or not.
- statuses_count : The number of statuses updated by the user.
- lang : The language of the account.
- status : Fetches the latest status updated by the user.
- contributors_enabled : Indicates whether the contributors are enabled or not.
- is_translator : Indicates whether there is a translator or not.
- is_translation_enabled : Indicates whether the translation is available or not.
- profile_background_color : The background color of the profile.
- profile_background_image_url : The URL of the background image of the profile.
- profile_background_image_url_https : The secure URL of the background image of the profile.
- profile_background_tile : The title of the background profile.
- profile_image_url : The URL of the profile image.
- profile_image_url_https : The secure URL of the profile image.
- profile_banner_url : The URL of the profile banner.
- profile_link_color : The color of the profile link.
- profile_sidebar_border_color : The color of the profile sidebar border.
- profile_sidebar_fill_color : The color of the profile sidebar.
- profile_text_color : The color of the profile text.
- profile_use_background_image : Indicates whether the profile is to use a background image or not.
- has_extended_profile : Indicates whether the profile is extended or not.
- default_profile : The default profile.
- default_profile_image : The image of the default profile.
- following : Indicates whether the authenticated user is following the user or not.
- follow_request_sent : Indicates whether the authenticated user has requested to follow the user or not.
- notifications: Indicates whether the authenticated user has turned on the notifications for the user or not.
示例:考虑 GeeksforGeeks 的 twitter 帐户。使用get_user()
方法获取用户。
# 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 screen name of the user
screen_name = "geeksforgeeks"
# fetching the user
user = api.get_user(screen_name)
# printing the information
print("The id is : " + str(user.id))
print("The id_str is : " + user.id_str)
print("The name is : " + user.name)
print("The screen_name is : " + user.screen_name)
print("The location is : " + str(user.location))
print("The profile_location is : " + str(user.profile_location))
print("The description is : " + user.description)
print("The url is : " + user.url)
print("The entities are : " + str(user.entities))
print("Is the account protected? : " + str(user.protected))
print("The followers_count is : " + str(user.followers_count))
print("The friends_count is : " + str(user.friends_count))
print("The listed_count is : " + str(user.listed_count))
print("The account was created on : " + str(user.created_at))
print("The favourites_count is : " + str(user.favourites_count))
print("The utc_offset is : " + str(user.utc_offset))
print("The geo_enabled is : " + str(user.geo_enabled))
print("The verified is : " + str(user.verified))
print("The statuses_count is : " + str(user.statuses_count))
print("The lang is : " + str(user.lang))
print("The status ID is : " + str(user.status.id))
print("The contributors_enabled is : " + str(user.contributors_enabled))
print("The is_translator is : " + str(user.is_translator))
print("The is_translation_enabled is : " + str(user.is_translation_enabled))
print("The profile_background_color is : " + user.profile_background_color)
print("The profile_background_image_url is : " + user.profile_background_image_url)
print("The profile_background_image_url_https is : " + user.profile_background_image_url_https)
print("The profile_background_tile is : " + str(user.profile_background_tile))
print("The profile_image_url is : " + user.profile_image_url)
print("The profile_image_url_https is : " + user.profile_image_url_https)
print("The profile_banner_url is : " + user.profile_banner_url)
print("The profile_link_color is : " + user.profile_link_color)
print("The profile_sidebar_border_color is : " + user.profile_sidebar_border_color)
print("The profile_sidebar_fill_color is : " + user.profile_sidebar_fill_color)
print("The profile_text_color is : " + user.profile_text_color)
print("The profile_use_background_image is : " + str(user.profile_use_background_image))
print("The has_extended_profile is : " + str(user.has_extended_profile))
print("The default_profile is : " + str(user.default_profile))
print("The default_profile_image is : " + str(user.default_profile_image))
print("Is the authenticated user following the account? : " + str(user.following))
print("Has the authenticated user requested to follow the account? : " + str(user.follow_request_sent))
print("Are notifications of the authenticated user turned on for the account? : " + str(user.notifications))
输出 :
The id is : 57741058
The id_str is : 57741058
The name is : GeeksforGeeks
The screen_name is : geeksforgeeks
The location is : India
The profile_location is : None
The description is : Your one-stop destination to attain Coding Nirvana…
The url is : http://t.co/k2iUfxLRBj
The entities are : {‘url’: {‘urls’: [{‘url’: ‘http://t.co/k2iUfxLRBj’, ‘expanded_url’: ‘http://geeksforgeeks.org/’, ‘display_url’: ‘geeksforgeeks.org’, ‘indices’: [0, 22]}]}, ‘description’: {‘urls’: []}}
Is the account protected? : False
The followers_count is : 17706
The friends_count is : 11
The listed_count is : 142
The account was created on : 2009-07-17 20:02:09
The favourites_count is : 465
The utc_offset is : None
The geo_enabled is : False
The verified is : False
The statuses_count is : 13231
The lang is : None
The status ID is : 1271404442068422662
The contributors_enabled is : False
The is_translator is : False
The is_translation_enabled is : False
The profile_background_color is : FFFDF7
The profile_background_image_url is : http://abs.twimg.com/images/themes/theme13/bg.gif
The profile_background_image_url_https is : https://abs.twimg.com/images/themes/theme13/bg.gif
The profile_background_tile is : False
The profile_image_url is : http://pbs.twimg.com/profile_images/1138375574726955008/1fNUyEdv_normal.png
The profile_image_url_https is : https://pbs.twimg.com/profile_images/1138375574726955008/1fNUyEdv_normal.png
The profile_banner_url is : https://pbs.twimg.com/profile_banners/57741058/1591281311
The profile_link_color is : 119E39
The profile_sidebar_border_color is : D3D2CF
The profile_sidebar_fill_color is : E3E2DE
The profile_text_color is : 0D0C0C
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。