In this article we will see how we can get the screen name of a user. Screen name is the username of the twitter account. It is the name that users choose to identify themselves on the network. Many users choose to either use their real name as the basis for their screen name, often in a shortened version. All the screen names must be unique.
Identifying the screen name in the GUI :
In the above mentioned profile, neveropen is the screen name of the profile.
In order to get the screen name we have to do the following :
- Identify the user ID of the profile.
- Get the User object of the profile using the
get_user()
method and the user ID.- From this object, fetch the screen_name attribute present in it.
Example 1: Consider the following profile :
The user ID of the above mentioned profile is 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 screen name screen_name = user.screen_name print ( "The screen name of the user is : " + screen_name) |
Output :
The screen name of the user is : neveropen
Example 2: Consider the following profile :
The user ID of the above mentioned profile is 4802800777.
# the ID of the user id = 4802800777 # fetching the user user = api.get_user( id ) # fetching the screen name screen_name = user.screen_name print ( "The screen name of the user is : " + screen_name) |
Output :
The screen name of the user is : PracticeGfG
<!–
–>
Please Login to comment…