Barry Barry - 3 months ago 54
Python Question

How to get screen name instead of user ID with tweepy

I'm printing out the tweets from my twitter feed to a CSV and want to get the CSV to show the username instead of the user ID.

My code uses tweepy.

outtweets.append([tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")])


This is what I use in my loop to get the user ID.
How would I go about to get the screen name instead?

Answer

See https://dev.twitter.com/overview/api/tweets Tweet object and https://dev.twitter.com/overview/api/users User object.

This will reveal that you need to use:

tweet.user.name

to access the user name