Skip to content

Instantly share code, notes, and snippets.

@vik-y
Forked from davej/delete_all_tweets.py
Last active September 22, 2023 21:04
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save vik-y/2669797e93a0615ef970 to your computer and use it in GitHub Desktop.
Save vik-y/2669797e93a0615ef970 to your computer and use it in GitHub Desktop.
This script will delete all of the tweets in a specified account.
# -*- coding: utf-8 -*-
"""
This script is forked originally from Dave Jeffery. The original implementation
was very slow and deleted around 2 tweets per second. Making it multithreaded I
am able to delete 30-50 tweets per second.
@author: vik-y
----------------------------------------------------------------------------
This script will delete all of the tweets in the specified account.
You may need to hit the "more" button on the bottom of your twitter profile
page every now and then as the script runs, this is due to a bug in twitter.
You will need to get a consumer key and consumer secret token to use this
script, you can do so by registering a twitter application at https://dev.twitter.com/apps
@requirements: Python 2.5+, Tweepy (http://pypi.python.org/pypi/tweepy/1.7.1)
@author: Dave Jeffery
---------------------------------------------------------
"""
import tweepy
import thread
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
def deleteThread(api, objectId):
try:
api.destroy_status(objectId)
print "Deleted:", objectId
except:
print "Failed to delete:", objectId
def oauth_login(consumer_key, consumer_secret):
"""Authenticate with twitter using OAuth"""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_url = auth.get_authorization_url()
verify_code = raw_input("Authenticate at %s and then enter you verification code here > " % auth_url)
auth.get_access_token(verify_code)
return tweepy.API(auth)
def batch_delete(api):
print "You are about to Delete all tweets from the account @%s." % api.verify_credentials().screen_name
print "Does this sound ok? There is no undo! Type yes to carry out this action."
do_delete = raw_input("> ")
if do_delete.lower() == 'yes':
for status in tweepy.Cursor(api.user_timeline).items():
try:
#api.destroy_status(status.id)
#print "Deleted:", status.id
thread.start_new_thread( deleteThread, (api, status.id, ) )
except:
print "Failed to delete:", status.id
if __name__ == "__main__":
#authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
print "Authenticated as: %s" % api.me().screen_name
batch_delete(api)
@katytootle
Copy link

can someone please do a screenshare or something with me to help me figure out how to do this? I'd greatly appreciate it. If you would like to be virtually compensated for your time, I'd be happy to do so. I'm so desperate to get this to work and I've been trying for DAYS.

@BitPopCoin
Copy link

Just pip install tweepy

@Nickfost
Copy link

@BitPopCoin that is the most useless piece of advice you could possibly give someone

@Beej126
Copy link

Beej126 commented Jun 20, 2016

for me this quickly ran into status code 429 = TOO_MANY_REQUESTS

@kevthanewversi
Copy link

Niiice! Excellent piece of multi threading code!

@mpahlevanzadeh
Copy link

Excellent, I did.

@anein
Copy link

anein commented Aug 1, 2018

How many threads will this code generate? o.O

@aybuketurker
Copy link

aybuketurker commented Jan 15, 2019

For this to work change thread to _thread and raw_input to input if you are using Python 3

@afabricioa
Copy link

this will delete all tweets?
i used once, says that i have 35k tweets but in the timeline shows "No tweets yet"

@ajithkumar-natarajan
Copy link

For this to work change thread to _thread and raw_input to input if you are using Python 3

Also enclose the print texts with parentheses

@murdoc02
Copy link

murdoc02 commented Feb 5, 2020

@kenhudak
Copy link

For this to work change thread to _thread and raw_input to input if you are using Python 3

Also for Python 3 I had to put the PRINT in parenthesis.

Although the script ran, it Failed to Delete every single Tweet.

@giron-dev
Copy link

For this to work change thread to _thread and raw_input to input if you are using Python 3

Also for Python 3 I had to put the PRINT in parenthesis.

Although the script ran, it Failed to Delete every single Tweet.

did you make sure to change thread to _thread where it says thread.start_new_thread?

I got it working for me after some trial and error.

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