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

标签 python twitter tweepy

我正在尝试编写一个脚本来关注 Twitter 上的人。 tweepy API 看起来不错,但我遇到了一些与从用户 ID 到屏幕名称的映射相关的不直观行为。

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'

什么给了?

最佳答案

发现这个问题不是一个简单的问题: http://code.google.com/p/twitter-api/issues/detail?id=214

已更新以供遇到相同问题的任何其他 tweepy 用户引用。

关于python - Tweepy API : how to get a user's id from a status SearchResult object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3256981/

相关文章:

python - 如何避免Python中的if语句多次重复条件?

python - 正则表达式拆分的 maxsplit 功能

python - 在python中拼接二值图像

html - Bootstrap 列元素调整大小碰撞到新行

php - Twitter REST API,更新状态?

python - tweepy流到sqlite数据库-语法错误

python - Popen stdout 读取管道,使用 sleep 死锁

Twitter 状态 ID

python - Tweepy 仅返回 76 条推文

Python/Tweepy UnicodeEncodeError