Easily, Delete your tweets from your Twitter account using python

If you want to delete your tweets from your twitter account then it is very easy to do using python.

TL;DR

Please follow these steps to delete your twitter’s tweet status:

Steps:

1: Install tweepy python library either using pip or conda python package manager.

2. Get your Consumer API key and Consumer API secret key from your twitter app.

3. Get your API access token & API secret token from your twitter app.

Python code:

import tweepy
CONSUMER_API_KEY = "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
CONSUMER_API_SECRET = "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
ACCESS_TOKEN ="xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
ACCESS_TOKEN_SECRET = "xxxxxxxx-xxxxxxxx-xxxxxxxx"
TWEET_LIMIT = 50
def oauth_token():
auth = tweepy.OAuthHandler(CONSUMER_API_KEY, CONSUMER_API_SECRET)
# auth_url = auth.get_authorization_url()
# verify_code = input("Authenticate at %s and then enter you verification code here > " % auth_url)
# auth.get_access_token(verify_code)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
return tweepy.API(auth)
def delete_tweets(tweet_limit=None):
print("Deleting tweets for user: {}".format(api.verify_credentials().screen_name))
delete_limit = tweet_limit or TWEET_LIMIT
count = 1
for status in tweepy.Cursor(api.user_timeline).items(delete_limit):
try:
api.destroy_status(status.id)
print("{}: Deleted status: {}".format(count, status.id))
count += 1
except Exception as e:
print(e)
if __name__ == "__main__":
print("Delete Tweets Function called!")
api = oauth_token()
delete_tweets(1000)