Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Tweet Deleter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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:

1. Obtain API credentials:
- Create a Twitter Developer account at https://developer.twitter.com/en/apps.
- Create a new app and generate the required API keys and access tokens.

2. Install the `tweepy` library:
```python
pip install tweepy
```

3. Download and extract your Twitter Archive:
- Go to your Twitter account settings.
- Under the "Your Twitter data" section, select "Download an archive of your data".
- Follow the instructions to receive an email with a download link.
- Download and extract the archive.

4. Write the Python script to delete tweets:
```python
import tweepy
import json

# Twitter API credentials
consumer_key = "YOUR_CONSUMER_KEY"
consumer_secret = "YOUR_CONSUMER_SECRET"
access_token = "YOUR_ACCESS_TOKEN"
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"

# Authenticate to Twitter
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# Create API object
api = tweepy.API(auth)

# Path to the extracted Twitter Archive JSON file
archive_path = "PATH_TO_YOUR_TWITTER_ARCHIVE/data/js/tweets/"

# Delete all tweets
with open(archive_path + "tweet.js", "r") as file:
tweets = json.load(file)

for tweet in tweets:
tweet_id = tweet["tweet"]["id_str"]
try:
api.destroy_status(tweet_id)
print(f"Deleted tweet with ID: {tweet_id}")
except tweepy.TweepError as e:
print(f"Failed to delete tweet with ID: {tweet_id}\nError: {e}")
```

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.

6. Run the script:
```python
python delete_tweets.py
```

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.
30 changes: 30 additions & 0 deletions Tweet Deleter/delete_tweets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import tweepy
import json

# Twitter API credentials
consumer_key = "YOUR_CONSUMER_KEY"
consumer_secret = "YOUR_CONSUMER_SECRET"
access_token = "YOUR_ACCESS_TOKEN"
access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"

# Authenticate to Twitter
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

# Create API object
api = tweepy.API(auth)

# Path to the extracted Twitter Archive JSON file
archive_path = "PATH_TO_YOUR_TWITTER_ARCHIVE/data/js/tweets/"

# Delete all tweets
with open(archive_path + "tweet.js", "r") as file:
tweets = json.load(file)

for tweet in tweets:
tweet_id = tweet["tweet"]["id_str"]
try:
api.destroy_status(tweet_id)
print(f"Deleted tweet with ID: {tweet_id}")
except tweepy.TweepError as e:
print(f"Failed to delete tweet with ID: {tweet_id}\nError: {e}")