2013-01-10 64 views
1

我对使用tweepy api非常新,并且设法为特定的未经认证的twitter用户获取followers_ids。我现在想知道如何获取twitter用户的所有follower_ids,因为第一次调用只给了我5000个id,而且用户拥有更多的followers。我已经通过tweepy文档,但仍然不清楚如何使用tweepy光标实际执行分页。我真的很感谢一个简单的解释,如何执行分页和一些帮助我的当前代码执行上述任务获取Twitter用户的所有followers_ids。而使用这种,我越来越使用正确的分页从twitter获取用户的所有followers_id

import tweepy 
    user = tweepy.api.get_user('someuser') 
    cursors = tweepy.Cursor(user.followers_ids, id='screen_name') 
    for cursor in cursors.items(): 
     print cursor.screen_name 

一个错误是:

tweepy.error.TweepError:此方法不执行分页

任何帮助,将不胜感激。

回答

2

我认为你需要首先有一个认证的tweepy.API实例。我得到了同样的错误,当我试图

user = api.get_user('username') 
c = tweepy.Cursor(user.follower_ids) 

然而,这个工作对我来说:

import tweepy 
## first set up authenticated API instance 
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(access_token_key, access_secret) 
api = tweepy.API(auth) 

for block in tweepy.Cursor(api.followers_ids, 'username').items(): 
    ## do something with the block of 5000 follower ids 

希望帮助!

相关问题