· 6 years ago · Dec 22, 2018, 06:52 PM
1import tweepy
2
3CONSUMER_API_KEY = "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
4CONSUMER_API_SECRET = "xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
5
6ACCESS_TOKEN ="xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx"
7ACCESS_TOKEN_SECRET = "xxxxxxxx-xxxxxxxx-xxxxxxxx"
8
9TWEET_LIMIT = 50
10
11def oauth_token():
12 auth = tweepy.OAuthHandler(CONSUMER_API_KEY, CONSUMER_API_SECRET)
13# auth_url = auth.get_authorization_url()
14
15# verify_code = input("Authenticate at %s and then enter you verification code here > " % auth_url)
16# auth.get_access_token(verify_code)
17 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
18
19 return tweepy.API(auth)
20def delete_tweets(tweet_limit=None):
21 print("Deleting tweets for user: {}".format(api.verify_credentials().screen_name))
22 delete_limit = tweet_limit or TWEET_LIMIT
23 count = 1
24 for status in tweepy.Cursor(api.user_timeline).items(delete_limit):
25 try:
26 api.destroy_status(status.id)
27 print("{}: Deleted status: {}".format(count, status.id))
28 count += 1
29 except Exception as e:
30 print(e)
31
32
33if __name__ == "__main__":
34 print("Delete Tweets Function called!")
35 api = oauth_token()
36 delete_tweets(1000)