简体   繁体   中英

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? Specifically, I'm using python and 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. 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.

I do not know about tweepy. But twitter's REST API limits results. At the end of result it gives some kind of pointer to next page. Use that pointer :) 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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