user3527949
user3527949

Reputation: 133

How to get Twitter followers list?

I am working on a web scraping project and would like to get the follower data from a public Twitter account. I usually find the request URL but I can't seem to find it on Twitter. So I am wondering how I can get the list of followers. I am using Python 3

Upvotes: 0

Views: 7485

Answers (1)

mikeybeck
mikeybeck

Reputation: 582

This page describes how to do it.

You'll need to install tweepy and use the following code:

import tweepy
import time
#insert your Twitter keys here
consumer_key ='xxxxxxx'
consumer_secret='xxxxxxx'
access_token='xxxxxxx'
access_token_secret='xxxxxxx'
twitter_handle='handle'

auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

list= open('twitter_followers.txt','w')

if(api.verify_credentials):
    print ('We successfully logged in')

user = tweepy.Cursor(api.followers, screen_name=twitter_handle).items()

while True:
    try:
        u = next(user)
        list.write(u.screen_name +' \n')

    except:
        time.sleep(15*60)
        print ('We got a timeout ... Sleeping for 15 minutes')
        u = next(user)
        list.write(u.screen_name +' \n')
list.close()

Upvotes: 3

Related Questions