有没有办法访问列表中的所有成员?目前,我只能看到前 20 名成员吗?具体来说,我使用的是 python 和 tweepy。
问问题
5919 次
3 回答
12
在 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...
我希望我可以为您链接一些最新的文档,但我唯一能找到的是关于使用 Cursors 的 1.4 版文档。这种策略仍然是推荐的对 Tweepy 中 Twitter API 资源的结果进行分页/迭代的方法。
于 2012-02-27T06:00:34.607 回答
1
我不知道tweepy。但是 twitter 的 REST API 限制了结果。在结果的最后,它给出了某种指向下一页的指针。使用该指针:) https://dev.twitter.com/docs/api
于 2011-11-09T00:38:44.217 回答
0
尝试一下:
user = tweepy.api.get_user('you or nick')
print user.screen_name
print user.followers_count
for friend in user.friends():
print friend.screen_name
于 2012-10-12T14:40:31.613 回答