User ID to Username tweepy

Amro elaswar picture Amro elaswar · Mar 24, 2015 · Viewed 24.3k times · Source

Can someone please tell me how to get one username from one id on tweepy? I have looked everywhere and can't find anything.

Answer

Juan E. picture Juan E. · Mar 24, 2015

If you just have a user_id value you need to call the twitter API with the get_user(user_id) method. The returned User object will contain the username under screen_name.

# steps not shown where you set up api
u = api.get_user(783214)
print u.screen_name

If you already have the User object from another API call just look for the screen_name.