Skip to content

Instantly share code, notes, and snippets.

@peterdalle
Created September 13, 2016 20:21
Show Gist options
  • Save peterdalle/bfebd334a59e4465cedb51b7eb05002c to your computer and use it in GitHub Desktop.
Save peterdalle/bfebd334a59e4465cedb51b7eb05002c to your computer and use it in GitHub Desktop.
Delete all Twitter direct messages
#!/usr/bin/python2
# Credit: https://gist.github.com/nileshgr/3388917
# Go to dev.twitter.com/apps and create a new app; put the information here.
# You need the tweepy library.
consumer_secret = ''
consumer_key = ''
access_token_key = ''
access_token_secret = ''
import tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth)
def deleteDMs():
while True:
dlist = api.direct_messages()
if len(dlist) >= 1:
for d in dlist:
print "Destroying " + d.text + "\n"
d.destroy()
else:
break
while True:
dlist = api.sent_direct_messages()
if(dlist) >= 1:
for d in dlist:
print "Destroying " + d.text + "\n"
d.destroy()
else:
break
deleteDMs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment