简体   繁体   English

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

[英]How to get all users in a list Twitter API?

Is there a way to access all members in a list? 有没有办法访问列表中的所有成员? Currently, I can only see the first 20 members? 目前,我只能看到前20名成员? Specifically, I'm using python and tweepy. 具体来说,我正在使用python和tweepy。

In Tweepy, this can be facilitated by using the Cursor class Tweepy provides, which implements an appropriate iterator for the model returned to you depending on your desired method call. 在Tweepy中,可以通过使用Tweepy提供的Cursor类来促进这一点,它根据您所需的方法调用为返回给您的模型实现适当的迭代器。 In your case, you want to initialize a Cursor with the list_members() method and parameters for the list owner and the list slug (see https://dev.twitter.com/docs/api/1/get/lists/members ). 在您的情况下,您希望使用list_members()方法以及列表所有者和列表段的参数初始化Cursor(请参阅https://dev.twitter.com/docs/api/1/get/lists/members ) 。

Example (modified from http://packages.python.org/tweepy/html/code_snippet.html#pagination ): 示例(从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...

I wish I could link you some up-to-date documentation, but the only thing I can find is this version 1.4 documentation about using Cursors . 我希望我可以链接到一些最新的文档,但我唯一能找到的是关于使用游标的1.4文档 This strategy is still the recommended way of doing pagination/iteration of results from the Twitter API resources in Tweepy. 这种策略仍然是在Tweepy中对Twitter API资源进行分页/迭代结果的推荐方法。

I do not know about tweepy. 关于tweepy,我不知道。 But twitter's REST API limits results. 但是twitter的REST API限制了结果。 At the end of result it gives some kind of pointer to next page. 在结果的末尾,它给出了下一页的某种指针。 Use that pointer :) https://dev.twitter.com/docs/api 使用该指针:) https://dev.twitter.com/docs/api

Try it: 试试吧:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM