skip to Main Content

How can I get a list of followers from a Twitter account with a lot of followers? My code is meant to get followers from a user and then follow them but max I can get and follow is 200 with my code and then after 200 it gets new users but way slower. Is there a way to get thousands more?

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

2

Answers


  1. Twitter documentation says there is a limit of 200 to the count parameter of the api. I would guess that is causing you your trouble.

    The number of users to return per page, up to a maximum of 200. Defaults to 20.

    Login or Signup to reply.
  2. Check your Twitter rate limits.

    Servers normally have a limit on the number of calls you can make to them before they begin to restrict access. The reason for this is that if they let every server ping them 1000+ times a minute, the cost of their servers will be higher and it will make it harder to spot a DNS attack (aggressive servers have a high limit of calls they can make while still looking like non-aggressive servers).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search