Skip to content

Commit 24cd2e7

Browse files
Added script to delete all your tweets
fixes #1433
1 parent 2717a2c commit 24cd2e7

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

Tweet Deleter/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
To delete all tweets using Twitter Archive and Python, you can utilize the Twitter API with the help of the `tweepy` library. However, please note that deleting tweets is a permanent action and cannot be undone. Make sure you have a backup of your tweets if needed. Here's a step-by-step guide:
2+
3+
1. Obtain API credentials:
4+
- Create a Twitter Developer account at https://developer.twitter.com/en/apps.
5+
- Create a new app and generate the required API keys and access tokens.
6+
7+
2. Install the `tweepy` library:
8+
```python
9+
pip install tweepy
10+
```
11+
12+
3. Download and extract your Twitter Archive:
13+
- Go to your Twitter account settings.
14+
- Under the "Your Twitter data" section, select "Download an archive of your data".
15+
- Follow the instructions to receive an email with a download link.
16+
- Download and extract the archive.
17+
18+
4. Write the Python script to delete tweets:
19+
```python
20+
import tweepy
21+
import json
22+
23+
# Twitter API credentials
24+
consumer_key = "YOUR_CONSUMER_KEY"
25+
consumer_secret = "YOUR_CONSUMER_SECRET"
26+
access_token = "YOUR_ACCESS_TOKEN"
27+
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
28+
29+
# Authenticate to Twitter
30+
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
31+
auth.set_access_token(access_token, access_token_secret)
32+
33+
# Create API object
34+
api = tweepy.API(auth)
35+
36+
# Path to the extracted Twitter Archive JSON file
37+
archive_path = "PATH_TO_YOUR_TWITTER_ARCHIVE/data/js/tweets/"
38+
39+
# Delete all tweets
40+
with open(archive_path + "tweet.js", "r") as file:
41+
tweets = json.load(file)
42+
43+
for tweet in tweets:
44+
tweet_id = tweet["tweet"]["id_str"]
45+
try:
46+
api.destroy_status(tweet_id)
47+
print(f"Deleted tweet with ID: {tweet_id}")
48+
except tweepy.TweepError as e:
49+
print(f"Failed to delete tweet with ID: {tweet_id}\nError: {e}")
50+
```
51+
52+
5. Replace the placeholders (`YOUR_CONSUMER_KEY`, `YOUR_CONSUMER_SECRET`, `YOUR_ACCESS_TOKEN`, `YOUR_ACCESS_TOKEN_SECRET`, and `PATH_TO_YOUR_TWITTER_ARCHIVE`) in the script with your actual API credentials and the path to the extracted Twitter Archive folder.
53+
54+
6. Run the script:
55+
```python
56+
python delete_tweets.py
57+
```
58+
59+
The script will iterate over each tweet in your Twitter Archive and attempt to delete it using the Twitter API. It will print the tweet ID for successfully deleted tweets and any errors encountered for failed deletions.

Tweet Deleter/delete_tweets.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import tweepy
2+
import json
3+
4+
# Twitter API credentials
5+
consumer_key = "YOUR_CONSUMER_KEY"
6+
consumer_secret = "YOUR_CONSUMER_SECRET"
7+
access_token = "YOUR_ACCESS_TOKEN"
8+
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
9+
10+
# Authenticate to Twitter
11+
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
12+
auth.set_access_token(access_token, access_token_secret)
13+
14+
# Create API object
15+
api = tweepy.API(auth)
16+
17+
# Path to the extracted Twitter Archive JSON file
18+
archive_path = "PATH_TO_YOUR_TWITTER_ARCHIVE/data/js/tweets/"
19+
20+
# Delete all tweets
21+
with open(archive_path + "tweet.js", "r") as file:
22+
tweets = json.load(file)
23+
24+
for tweet in tweets:
25+
tweet_id = tweet["tweet"]["id_str"]
26+
try:
27+
api.destroy_status(tweet_id)
28+
print(f"Deleted tweet with ID: {tweet_id}")
29+
except tweepy.TweepError as e:
30+
print(f"Failed to delete tweet with ID: {tweet_id}\nError: {e}")

0 commit comments

Comments
 (0)