【问题标题】:Obtain all followers_ids of a user from twitter using correct pagination使用正确的分页从 twitter 获取用户的所有 follower_id
【发布时间】:2013-01-10 03:24:26
【问题描述】:

我对使用 tweepy api 非常陌生,并且设法为特定的未经身份验证的 Twitter 用户获取了 follower_ids。我现在想知道如何获取 twitter 用户的所有 follower_id,因为第一次调用只给了我 5000 个 id,并且用户有更多的关注者。我已经浏览了 tweepy 文档,但仍然不清楚如何使用 tweepy 光标实际执行分页。我非常感谢对如何执行分页的简单解释以及对我当前代码的一些帮助,以执行上述获取 twitter 用户的所有 follower_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: 该方法不执行分页

任何帮助将不胜感激。

【问题讨论】:

    标签: python twitter pagination tweepy


    【解决方案1】:

    我认为您首先需要有一个经过身份验证的 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
    

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      相关资源
      最近更新 更多