Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Last active December 15, 2022 13:57
Show Gist options
  • Save dedunumax/91992ac6f1940be5d391 to your computer and use it in GitHub Desktop.
Save dedunumax/91992ac6f1940be5d391 to your computer and use it in GitHub Desktop.
Remove all the followers from your twitter account.
import tweepy
__author__ = 'dedunumax'
'''
This script will remove all the followers from your twitter account. For that first it will block user one by one and
then unblock them. If you are following your followers, you won't be subscribed to them anymore once you run this job.
Rub this script carefully.
Install tweepy module using pip. To install tweepy run below command in your terminal.
sudo pip install tweepy
Please replace consumer_key and consumer_secret. Visit https://apps.twitter.com to get your consumer_key and
consumer_secret.
Once you generate consumer key create an access token from same twitter page. Replace access_token and
access_token_secret with provided values. Then run the script.
'''
consumer_key = '<consumer_key>'
consumer_secret = '<consumer_secret>'
access_token = '<access_token>'
access_token_secret = '<access_token_secret>'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
followers_list = api.followers_ids(api.me())
for user in followers_list:
api.create_block(user)
api.destroy_block(user)
print user
@jonnynabb
Copy link

Can you add a line to remove accounts you follow, so that this only removes accounts that you havent followed ?

Copy link

ghost commented Aug 18, 2022

My updated version of this script, cause it didn't fully work for me. So if it doesn't work for anyone else either, here you go:

import tweepy

consumer_key = '<consumer_key>'
consumer_secret = '<consumer_secret>'
access_token = '<access_token>'
access_token_secret = '<access_token_secret>'

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

api = tweepy.API(auth)

followers = []
for page in tweepy.Cursor(api.get_follower_ids, screen_name="<You're screen name here>").pages():
    followers.extend(page)

for user in followers:
    api.create_block(user_id=user)
    api.destroy_block(user_id=user)
    print(user)

@dedunumax
Copy link
Author

Thanks a lot! My example stopped working after few months.

Copy link

ghost commented Aug 23, 2022

You're welcome! That's what Open Source is for.

@xieem
Copy link

xieem commented Dec 15, 2022

Hi could you update this with the new key issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment