Tweepy API:如何从状态 SearchResult 对象获取用户 ID?

7 投票
1 回答
8247 浏览
提问于 2025-04-16 01:21

我正在尝试写一个脚本,用来在推特上关注别人。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'

这是怎么回事呢?

1 个回答

7

我发现这个问题不是tweepy造成的:

这里有个链接,可以参考一下,地址是:http://code.google.com/p/twitter-api/issues/detail?id=214

我更新这个信息是为了帮助其他遇到同样问题的tweepy用户。

撰写回答