Skip to content

Instantly share code, notes, and snippets.

@ihpannu
Last active March 31, 2022 14:13
Show Gist options
  • Save ihpannu/372788f40d9e7f12bd4baea195a14095 to your computer and use it in GitHub Desktop.
Save ihpannu/372788f40d9e7f12bd4baea195a14095 to your computer and use it in GitHub Desktop.
Python script to delete all tweets using Python version 3
import tweepy
import _thread
consumer_key = ''
consumer_secret = ''
access_key = ''
access_secret = ''
def deleteThread(api, objectId):
try:
api.destroy_status(objectId)
print("Deleted:", objectId)
except:
print("Failed to delete:", objectId)
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 = 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 = 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
_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)
@theConjurer14
Copy link

Hi! Running this I'm getting

tweepy.error.TweepError: [{'message': 'You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve', 'code': 453}]

Is it mandatory to request access to Elevated API?

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