Python Tweepy – Getting the location of a user
In this article we will see how we can get the location of a user. The location of the user account need not be the exact physical location of the user. As the user is free to change their location, the location of the account can even by a hypothetical place. The location attribute is optional and is Nullable.
Identifying the location in the GUI :
In the above mentioned profile, India is the location of the profile.
In order to get the location 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 location attribute present in it.
Example 1: Consider the following profile :
We will use the user ID to fetch the user. The user ID of the above mentioned profile is 57741058.
The location of the user is : India
Example 2: Consider the following profile :
We will use the screen name to fetch the user. The screen name of the above mentioned profile is PracticeGfG. Here the location is not mentioned.
The user has not mentioned their location.