How to get all users in a list Twitter API?

2024/9/20 5:58:04

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.

Answer

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

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

https://en.xdnf.cn/q/72528.html

Related Q&A

Python adding a blank/empty column. csv

Hello I have a database that i am trying to make a .csv file quickly from.my data looks like this.Song_Name,File_Name,Artist_Name,Artist_ID Song1,filename1,artistname,artist001 Song1,filename1,artistna…

Displaying Radio buttons horizontally in matplotlib

I am using the matplotlib.widgets to create radio buttons in my widgets, the buttons coming are stacked vertically, I would like them to be stacked horizontally.MVCE:import matplotlib.pyplot as plt fro…

Python MemoryError on large array

This is the python script that Im trying to run:n = 50000000000 ##50 billion b = [0]*n for x in range(0,n):b[x] = random.randint(1,899999)... But the output Im getting is:E:\python\> python sort.py…

How to generate a PDF with non-ascii characters using from_string from python-pdfkit

Im struggling to generate just a simple PDF with non-ascii characters using Python 3.5.2, python-pdfkit and wkhtmltox-0.12.2.This is the easiest example I could write:import pdfkit html_content = u<…

Minimum window of days required to travel all cities

This is an interesting question that I came across in a coding challenge:There are k cities and n days. A travel agent is going to show you city k on day n. Youre supposed to find the minimum number of…

Force Nosetests to Use Python 2.7 instead of 3.4

Ive been learning Python using version 3.4. I recently started learning Web.py so have been using Python 2.7 for that, since web.py not supported in Python 3.4. I have nose 1.3.4 module installed for …

Python regex not to match http://

I am facing a problem to match and replace certain words, not contained in http:// Present Regex: http://.*?\s+This matches the pattern http://www.egg1.com http://www.egg2.com I need a regex to matc…

how can I maintain sequence of my list using set?

In [1]: l1 = [a,2,3,0,9.0,0,2,6,b,a]In [2]: l2 = list(set(l1))In [3]: l2 Out[3]: [a, 0, 2, 3, 6, 9.0, b]Here you can see the the list l2 is falling with different sequence then the original l1, I need …

How to reference a dict object?

I have a Python dict object d. d = {a: 1, b: 2, c: 3}. My problem is really simple. I want to reference a variable to the elements of d. For example, something like:In[1]: p = d[a] >>> p = 1 I…

Python 3.3: DeprecationWarning when using nose.tools.assert_equals

I am using nosetest tools for asserting a python unittest:... from nose.tools import assert_equals, assert_almost_equalclass TestPolycircles(unittest.TestCase):def setUp(self):self.latitude = 32.074322…