【问题标题】:Tweepy API: how to get a user's id from a status SearchResult object?Tweepy API:如何从状态 SearchResult 对象中获取用户 ID?
【发布时间】:2011-03-16 11:30:11
【问题描述】:

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

什么给了?

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-10-05
      • 2022-12-11
      • 1970-01-01
      • 2013-03-04
      • 2019-12-25
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多