【问题标题】:Tweepy: How can I get more than 20 tweets from a user?Tweepy:如何从用户那里获得超过 20 条推文?
【发布时间】:2017-01-30 21:38:49
【问题描述】:

根据their docs

API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])

Returns the 20 most recent statuses posted from the authenticating user or the user specified. It’s also possible to request another user’s timeline via the id parameter.

那么我怎样才能从一个人的时间线上获得超过 20 条推文呢?文档没有显示如何...该用户需要进行身份验证吗?

【问题讨论】:

    标签: twitter tweepy


    【解决方案1】:

    您可以在API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page]) 中使用pages 参数。对于page 值 1,您将从用户时间线获得一组最新的 20 条推文,然后在进一步的迭代中,当我们增加 page = 2 的值时,该方法返回其他 20 条推文,这些推文比最旧的推文更旧从第 1 页收到,您可以将其视为:

    假设您的帐户中有 120 条推文(第 1 条推文是最旧的,第 120 条是最新的),那么:

    page = 1 将返回 (100, 120]

    page = 2 将返回 (80, 100]

    ...等等

    我希望您已经了解了页面的概念,现在是时候实现这些内容了。

    no_of_pages = int(raw_input("Please enter the number of tweets: "))
    for i in xrange(no_of_pages):
        API.user_timeline("@anmoluppal366", page = i)
    

    【讨论】:

    • 你知道如何使用 Ruby 做到这一点吗?
    • 你为什么这么厉害? @anmol_uppal
    • page 不再是此方法中的有效参数,请检查 here。而且,请记住,您只能获取最新的 3200 条推文。如果你想得到更多,还需要其他方法。
    【解决方案2】:

    您也可以使用 max_id 参数。类似的东西

    r0 = api.user_timeline("@donaldtrump") # gives 20 latest tweets
    idlast = r0[-1].id # the last id of these 20
    r1 = api.user_timeline("@donaldtrump", max_id = idlast) # next 20 tweets older or same age as idlast
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-10
      相关资源
      最近更新 更多