【问题标题】:How can I get a large list of followers from a Twitter user and then follow them?如何从 Twitter 用户那里获得大量关注者列表,然后关注他们?
【发布时间】:2019-05-29 13:09:31
【问题描述】:

如何从拥有大量关注者的 Twitter 帐户获取关注者列表?我的代码旨在从用户那里获得关注者,然后关注他们,但我的代码最多可以获得和关注 200 个,然后在 200 个之后它会获得新用户,但速度会慢一些。有没有办法获得更多?

import tweepy
from time import sleep

consumer_key = ''
consumer_secret = ''
access_key = ''
access_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)

api = tweepy.API(auth)

users = tweepy.Cursor(api.followers, screen_name='twitter', count=200).items()
count = 0

while True:
    try:
        user = next(users)
        api.create_friendship(user.screen_name)
        sleep(1)
        print(user.screen_name)

    except tweepy.TweepError as e:
        if e.api_code == 161:
            while(count < 901):
                print(count, end='\r')
                sleep(1)
                count +=1
        if e.api_code == 160:
            pass
    except StopIteration:
        pass

【问题讨论】:

    标签: python python-3.x twitter tweepy


    【解决方案1】:

    Twitter documentation 表示 api 的 count 参数有 200 个限制。我猜这给你带来了麻烦。

    每页返回的用户数,最多 200 个。默认为 20 个。

    【讨论】:

      【解决方案2】:

      检查您的Twitter rate limits.

      在开始限制访问之前,服务器通常会限制您可以对其进行的调用次数。这样做的原因是,如果他们让每台服务器每分钟 ping 超过 1000 次,他们的服务器成本会更高,并且更难发现 DNS 攻击(攻击性服务器可以进行的调用有很高的限制)虽然看起来仍然像非攻击性服务器)。

      【讨论】:

        猜你喜欢
        • 2021-02-27
        • 2013-08-28
        • 2021-08-19
        • 2017-10-20
        • 2021-04-14
        • 2012-12-12
        • 2015-09-09
        • 2012-07-20
        • 2015-06-20
        相关资源
        最近更新 更多