Tweepy:如何从用户那里获得超过 20 条推文?

Tweepy: How can I get more than 20 tweets from a user?

根据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 条推文呢?文档没有说明如何...该用户是否需要进行身份验证?

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

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

page = 1 would return (100, 120]

page = 2 would return (80, 100]

... and so on

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

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)

您也可以使用 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