如何获取列表中的所有用户 Twitter API? [英] How to get all users in a list Twitter API?

查看:34
本文介绍了如何获取列表中的所有用户 Twitter API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to access all members in a list? Currently, I can only see the first 20 members? Specifically, I'm using python and tweepy.

推荐答案

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

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. 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).

示例(修改自 http://packages.python.org/tweepy/html/code_snippet.html#分页):

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...

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

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. This strategy is still the recommended way of doing pagination/iteration of results from the Twitter API resources in Tweepy.

这篇关于如何获取列表中的所有用户 Twitter API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆