如何在列表Twitter API中获取所有用户?

Par*_*rth 3 python api twitter tweepy

有没有办法访问列表中的所有成员?目前,我只能看到前20名成员?具体来说,我正在使用python和tweepy.

jml*_*ane 8

在Tweepy中,可以通过使用Tweepy提供的Cursor类来促进这一点,它根据您所需的方法调用为返回给您的模型实现适当的迭代器.在您的情况下,您希望使用list_members()列表所有者和列表slug 的方法和参数初始化Cursor (请参阅https://dev.twitter.com/docs/api/1/get/lists/members).

示例(从http://packages.python.org/tweepy/html/code_snippet.html#pagination修改):

import tweepy
api = tweepy.API() # Don't forget to use authentication for private lists/users.

# Iterate through all members of the owner's list
for member in tweepy.Cursor(api.list_members, 'list_owner', 'slug').items():
    # Do something with member...
Run Code Online (Sandbox Code Playgroud)

我希望我可以链接到一些最新的文档,但我唯一能找到的是关于使用游标的1.4文档.这种策略仍然是在Tweepy中对Twitter API资源进行分页/迭代结果的推荐方法.