Skip to content

Instantly share code, notes, and snippets.

@jeekajoo
Forked from JohnTroony/delete_all_tweets.py
Last active February 18, 2022 17:31
Show Gist options
  • Save jeekajoo/582898fcc47d493b8ba6618d43699536 to your computer and use it in GitHub Desktop.
Save jeekajoo/582898fcc47d493b8ba6618d43699536 to your computer and use it in GitHub Desktop.
delete ALL tweets using tweepy

Delete ALL tweets

Modifications

  • Remove confirmations
  • Add README

How to use

vim delete_all_tweets.py # add credentials
virtualenv tweepy_venv
source tweepy_venv/bin/activate
tweepy_venv> pip install tweepy
tweepy_venv> #pip install --upgrade pip
tweepy_venv> python delete_all_tweets.py
#!/usr/bin/env python
# -*- 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)
@Original_author: Dave Jeffery
@Co-author: John Troon
"""
import tweepy
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
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 "Deleting all tweets from the account @%s." % api.verify_credentials().screen_name
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)
@jeekajoo
Copy link
Author

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