Вопрос

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top