Skip to content

Instantly share code, notes, and snippets.

@morisy
Forked from smortime/delete_tweets.py
Created January 9, 2017 05:15
Show Gist options
  • Save morisy/a5824698022d6e0bf1e55f72dfe6df71 to your computer and use it in GitHub Desktop.
Save morisy/a5824698022d6e0bf1e55f72dfe6df71 to your computer and use it in GitHub Desktop.
Script to delete all of your tweets. Requires Python 3.x, Twython, and API keys.
#Schuyler Mortimer
from twython import Twython
import sys
#get from twitter developer site
APP_KEY = ''
APP_SECRET = ''
TOKEN = ''
TOKEN_SECRET = ''
def batch_delete(twitter):
#ran into a 200 tweet limit, loop gets around this
while True:
#get the timeline
try:
timeline = twitter.get_user_timeline(count=200)
except:
print("You made a mistake.")
sys.exit()
if len(timeline) == 0:
print("No tweets left to delete")
break
#delete the timeline
for tweet in timeline:
status = int(tweet['id_str'])
twitter.destroy_status(id=status)
print('Tweet deleted: ' + str(status))
print(len(timeline))
def main():
twitter = Twython(APP_KEY, APP_SECRET, TOKEN, TOKEN_SECRET)
batch_delete(twitter)
if __name__ == '__main__':
main()
@swartik
Copy link

swartik commented Apr 20, 2019

Thanks! This worked the first time and did exactly what I wanted.

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