Python - User object in Tweepy - GeeksforGeeks

03 Jul, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
The User object in Tweepy module contains the information about a user.
Here are the list of attributes in the User object :
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.
Example : Consider the twitter account of GeeksforGeeks. Use get_user() method to fetch the user.
# import the moduleimport tweepy  # assign the values accordinglyconsumer_key = ""consumer_secret = ""access_token = ""access_token_secret = ""  # authorization of consumer key and consumer secretauth = 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 userscreen_name = "geeksforgeeks"  # fetching the useruser = api.get_user(screen_name)  # printing the informationprint("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))
Output :
The id is : 57741058The id_str is : 57741058The name is : GeeksforGeeksThe screen_name is : geeksforgeeksThe location is : IndiaThe profile_location is : NoneThe description is : Your one-stop destination to attain Coding Nirvana...The url is : http://t.co/k2iUfxLRBjThe 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? : FalseThe followers_count is : 17706The friends_count is : 11The listed_count is : 142The account was created on : 2009-07-17 20:02:09The favourites_count is : 465The utc_offset is : NoneThe geo_enabled is : FalseThe verified is : FalseThe statuses_count is : 13231The lang is : NoneThe status ID is : 1271404442068422662The contributors_enabled is : FalseThe is_translator is : FalseThe is_translation_enabled is : FalseThe profile_background_color is : FFFDF7The profile_background_image_url is : http://abs.twimg.com/images/themes/theme13/bg.gifThe profile_background_image_url_https is : https://abs.twimg.com/images/themes/theme13/bg.gifThe profile_background_tile is : FalseThe profile_image_url is : http://pbs.twimg.com/profile_images/1138375574726955008/1fNUyEdv_normal.pngThe profile_image_url_https is : https://pbs.twimg.com/profile_images/1138375574726955008/1fNUyEdv_normal.pngThe profile_banner_url is : https://pbs.twimg.com/profile_banners/57741058/1591281311The profile_link_color is : 119E39The profile_sidebar_border_color is : D3D2CFThe profile_sidebar_fill_color is : E3E2DEThe profile_text_color is : 0D0C0C
Python-Tweepy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Python program to convert a list to string
Reading and Writing to text files in Python