This is a simple script that helps you delete tweets (or just replies or retweets) from your timeline. There are quite a few third-party services that allow you to delete tweets, but these very likely will not allow you to delete tweets beyond the infamous 3,200 tweet limit.
Unfortunately, as of late 2018, you are required to have a Twitter Developer account in order to create a Twitter app.
- Create a Twitter Developer account:
- User profile: Use your current Twitter @username.
- Account details: Select I am requesting access for my own personal use, set your 'Account name' to your @username, and select your 'Primary country of operation.
- Use case details: select 'Other', and explain in at least 300 words that you want to create an app to semi-automatically clean up your own tweets.
- Terms of service: Read and accept the terms.
- Email verification: Confirm your email address.
- Now wait for your Twitter Developer account to be reviewed and approved (in my case this appeared to happen automatically, super good security over there).
- Create a new Twitter app (not available as long as your Twitter Developer account is pending review).
- Set 'Access permissions' of your app to Read and write.
- Open your Twitter Developer's apps.
- Click the 'Details' button next to your newly created app.
- Click the 'Keys and tokens' tab, and find your keys, secret keys and access tokens.
- Put these keys in a file called
credentials.json
(or whatever you want) like so:
{
"consumer_key": "[your consumer key]",
"consumer_secret": "[your consumer secret]",
"access_token_key": "[your access token]",
"access_token_secret": "[your access token secret]"
}
- Open the Your Twitter data page
- Scroll to the 'Download your Twitter data' section at the bottom of the page
- Re-enter your password
- Click 'Request data', and wait for the email to arrive
- Follow the link in the email to download your Tweet data
- Unpack the archive
Install the tool using pip
.
python3 -m pip install delete-tweets
Delete any tweet from before January 1, 2018:
delete-tweets delete --until 2018-01-01 tweet.js
Or only delete all retweets:
delete-tweets delete --filter retweets tweet.js
You can optionally spare tweets by passing a file of id_str
, setting a minimum
amount of likes or retweets:
delete-tweets delete --until 2018-01-01 tweet.js --spare-ids ids_to_spare.txt
Spare tweets that have at least 10 likes, or 5 retweets:
delete-tweets delete --until 2018-01-01 tweet.js --spare-min-likes 10 --spare-min-retweets 5
Note If you run this once and then want to run it again with the same file, you can use the --dry-run
output to get the IDs you removed before, with some shell trickery:
delete-tweets -v DEBUG delete --dry-run -j tweets.js -u 2018-01-01 --spare-min-likes 10 --spare-min-retweets 5 2>&1 | grep 'delete tweet' | sed 's/.*delete tweet //' > deleted_ids.txt