如何在tweepy中查询特定Twitter用户的最早n个粉丝?

时间:2016-12-02 04:21:11

标签: python twitter tweepy

我使用tweepy来查询Twitter粉丝。我唯一想留下的是最早的追随者。由于twitter以反向的时间顺序命令其关注者,我现在可以做的是查询所有关注者并存储在列表中,然后切片最后n个项目,这是非常低效的。有人对此有什么想法吗?

for page in tweepy.Cursor(api.followers, screen_name=specific_user).pages():
    for follower in page:
        # do something with follower

1 个答案:

答案 0 :(得分:0)

这个问题很老..但这是一个解决方案

查看GET followers/idsGET followers/list,我们看到Twitter以下列方式返回关注者:

  

目前,结果是按照最新的后续顺序排序的 - 但是,此顺序可能会受到突击更改和最终一致性问题的影响。结果以20个用户的组给出,并且可以通过在后续请求中使用next_cursor值来导航结果的多个“页面”。有关详细信息,请参阅使用游标导航集合。

我们看到Tweepy Cursor Tutorial

  

限制   如果您只想要返回n个项目或页面怎么办?您将要强加的限制传递给items()或pages()方法。

# Only iterate through the first 200 statuses
for status in tweepy.Cursor(api.user_timeline).items(200):
    process_status(status)

# Only iterate through the first 3 pages
for page in tweepy.Cursor(api.user_timeline).pages(3):
    process_page(page)

或者在这种情况下你想要这样的东西:

for user in tweepy.Cursor(constants.api.followers, screen_name="joerogan").items(200):
    print(user)