Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tweepy API: how to get a user's id from a status SearchResult object?

I'm trying to write a script to follow people on twitter. The tweepy API seems pretty good, but I'm running into some unintuitive behavior related to the mapping from user's ids to their screen names.

In [1]: import tweepy
In [2]: api = tweepy.API()

# get an arbitrary tweet
In [3]: tweet = api.search("anything")[0]

In [5]: tweet.text
Out[5]: 'Currently mourning the [potential] loss of around 500 pictures I took while in Oklahoma. Anyone know anything about Canon Rebels?'

# who tweeted it?
In [6]: tweet.from_user
Out[6]: 'helloregan'

# get the tweeters id
In [7]: tweet.from_user_id
Out[7]: 101962792

# i'm paranoid. just want to make sure its right.
In [8]: helloregan = api.get_user(user_id=tweet.from_user_id)           

# yep, same id.
In [9]: helloregan.id
Out[9]: 101962792

# lets check to see if its the same screen name? no. different person.
In [10]: helloregan.screen_name
Out[10]: 'kikiiputh'

What gives?

like image 365
user392870 Avatar asked Jul 15 '10 15:07

user392870


People also ask

How do I find my Tweepy status ID?

Identifying the ID in the GUI : In order to get the ID of a status, we have to do the following : Identify the status ID of the status from the GUI. Get the Status object of the status using the get_status() method with the status ID. From this object, fetch the id attribute present in it.

Which returns a single status specified by the ID parameter?

GET statuses/show/:id Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the Tweet.

What is status in Tweepy?

The Status object in Tweepy module contains the information about a status/tweet. Here are the list of attributes in the Status object : created_at : The time the status was posted. id : The ID of the status. id_str : The ID of the status as a string.

What does Tweepy return?

Returns full Tweet objects for up to 100 Tweets per request, specified by the id parameter.


1 Answers

Figured out the issue isn't a tweepy one: http://code.google.com/p/twitter-api/issues/detail?id=214

Updated for reference for any other tweepy users who run into the same issue.

like image 83
user392870 Avatar answered Sep 29 '22 10:09

user392870