Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tweepy user id from mention

I am using tweepy to set up a script that finds the latest mention of my username. From this, I want to retrieve the text of the tweet, and their twitter user name. However, I don't seem to be able to retrieve the actual @ username, only their id number. Any suggestions?

Below is my code. The question marks are where I need the proper syntax:

myMentions = tweepy.Cursor (api.mentions).items(1)

for mention in myMentions:
    statusText = mention.text
    statusUser = mention.????

Thanks so much!

like image 279
Joseph Brennan Avatar asked May 04 '13 17:05

Joseph Brennan


1 Answers

Here's what works for me with the most recent tweepy version:

import tweepy

auth = tweepy.OAuthHandler(<consumer_key>, <consumer_secret>)
auth.set_access_token(<key>, <secret>)

api = tweepy.API(auth)

mentions = api.mentions_timeline(count=1)

for mention in mentions:
    print mention.text
    print mention.user.screen_name

Hope that helps.

like image 148
alecxe Avatar answered Sep 20 '22 23:09

alecxe