小编use*_*870的帖子

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

我正在尝试编写一个脚本来关注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)           

# …
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy

7
推荐指数
1
解决办法
7173
查看次数

标签 统计

python ×1

tweepy ×1

twitter ×1