且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-28 22:38:04

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