How to get all users in a list Twitter API?

懵懂的女人 提交于 2019-12-06 06:49:59

问题


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.


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/8058858/how-to-get-all-users-in-a-list-twitter-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!