Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This script will delete all of the tweets in a specified account.
# -*- coding: utf-8 -*-
"""
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
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'
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
except:
print "Failed to delete:", status.id
if __name__ == "__main__":
api = oauth_login(CONSUMER_KEY, CONSUMER_SECRET)
print "Authenticated as: %s" % api.me().screen_name
batch_delete(api)
@imZack

This comment has been minimized.

Show comment Hide comment
@imZack

imZack Jul 25, 2014

Thank you! this saved my day!
ps. can't install tweepy from thier latest version on github. must use pip install.

imZack commented Jul 25, 2014

Thank you! this saved my day!
ps. can't install tweepy from thier latest version on github. must use pip install.

@argelouski

This comment has been minimized.

Show comment Hide comment
@argelouski

argelouski Oct 24, 2014

Nice script! I'm new to the twitter API. I deleted all tweets possible with this script, but that account still shows 8,5k tweets and all the tweets containing media (photos and videos) are available. The timeline of that account does not show up these tweets, that's why the method api,user_timeline does not retreive them. I'm not seeing anything in the documentation that helps me to get these tweets, maybe you have an idea?

Nice script! I'm new to the twitter API. I deleted all tweets possible with this script, but that account still shows 8,5k tweets and all the tweets containing media (photos and videos) are available. The timeline of that account does not show up these tweets, that's why the method api,user_timeline does not retreive them. I'm not seeing anything in the documentation that helps me to get these tweets, maybe you have an idea?

@JohnTroony

This comment has been minimized.

Show comment Hide comment
@JohnTroony

JohnTroony Apr 2, 2015

I've made some changes on the script https://gist.github.com/JohnTroony/489ccc8e476b9377ae47

I've made some changes on the script https://gist.github.com/JohnTroony/489ccc8e476b9377ae47

@vik-y

This comment has been minimized.

Show comment Hide comment
@vik-y

vik-y Sep 5, 2015

This can delete 1-2 tweets per second.

I forked this and made a much faster version of this using threads. It can delete upto 30-50 tweets per second.
https://gist.github.com/vik-y/2669797e93a0615ef970

vik-y commented Sep 5, 2015

This can delete 1-2 tweets per second.

I forked this and made a much faster version of this using threads. It can delete upto 30-50 tweets per second.
https://gist.github.com/vik-y/2669797e93a0615ef970

@adaro

This comment has been minimized.

Show comment Hide comment
@adaro

adaro Sep 8, 2015

Thank you!

adaro commented Sep 8, 2015

Thank you!

@nileshtrivedi

This comment has been minimized.

Show comment Hide comment
@nileshtrivedi

nileshtrivedi Aug 31, 2016

Getting same problem which @argelouski reported. Account shows 8K tweets, none in the main timeline but all are there in "Replies" and "Media".

One approach would be to download your complete Twitter archive, extract tweet IDs from them and delete those.

Getting same problem which @argelouski reported. Account shows 8K tweets, none in the main timeline but all are there in "Replies" and "Media".

One approach would be to download your complete Twitter archive, extract tweet IDs from them and delete those.

@charlesstricklin

This comment has been minimized.

Show comment Hide comment
@charlesstricklin

charlesstricklin Dec 13, 2016

I've tried this, and the forked version of this, and neither deletes any of my tweets. At least this version tells me that it cannot for about 28 instances, each followed by an 18-digit number, each beginning with 80xxxxxxxxxxxxxxxx. Any idea what's wrong and what to do to correct it?

I've tried this, and the forked version of this, and neither deletes any of my tweets. At least this version tells me that it cannot for about 28 instances, each followed by an 18-digit number, each beginning with 80xxxxxxxxxxxxxxxx. Any idea what's wrong and what to do to correct it?

@mpahlevanzadeh

This comment has been minimized.

Show comment Hide comment
@mpahlevanzadeh

mpahlevanzadeh Mar 15, 2017

I provided a secret key ,cunsomer key and verification code. But I don't how to run this script, Specialy I don't know where spread verification code.

I provided a secret key ,cunsomer key and verification code. But I don't how to run this script, Specialy I don't know where spread verification code.

@volshebnikRAJ

This comment has been minimized.

Show comment Hide comment
@volshebnikRAJ

volshebnikRAJ May 4, 2017

Hey, if you are till looking for a script to delete all tweets you can check this one out : https://github.com/volshebnikRAJ/tweepy-api

Hey, if you are till looking for a script to delete all tweets you can check this one out : https://github.com/volshebnikRAJ/tweepy-api

@catleeball

This comment has been minimized.

Show comment Hide comment
@catleeball

catleeball Jul 21, 2017

Small suggestion for line 35- maybe also accept "y" in addition to "yes" with something like:

if do_delete.lower() == 'yes' or do_delete.lower() == 'y':

Small suggestion for line 35- maybe also accept "y" in addition to "yes" with something like:

if do_delete.lower() == 'yes' or do_delete.lower() == 'y':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment