This is a simple script that enables you to delete tweets from your timeline. There are third-party services that allow you to delete tweets, but they will not allow you to delete tweets beyond the infamous 3,200 tweet limit.
Credit to @koenrh for the original project.
Note: 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: You will need to provide details of your use case:
- 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.
- 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.
- Now you need to make these keys and tokens available to your shell environment.
- Create a new
.env
file in the root of the project - Use the
.env-template
as a guide. - Replace the key, secrets and token with the values from Twitter.
- 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 to
twitter-archive
folder - The
tweets.js
should be discoverable at:./twitter-archive/data/tweets.js
You will need the following:
pyenv
to install the correct version of Python.virtualenv
to create isolated Python environment.
Install the required version of Python and setup a new virtual environment.
$ pyenv install
$ virtualenv .venv --prompt=delete-tweets
$ source .venv/bin/activate
(delete-tweets) $
Once you're in your isolated Python environment, you can upgrade and install dependencies.
pip install --upgrade pip
pip install -r requirements-dev.txt
You can then run the linter and unit tests:
flake8
pytest
Delete any tweet from before January 1, 2018:
python -m deletetweets --until 2018-01-01
Or only delete all retweets:
python -m deletetweets --filter retweets
Delete ALL tweets with a dry-run (to avoid a footgun):
python -m deletetweets --dry-run
Delete ALL tweets from a specific file with a dry-run:
python -m deletetweets --dry-run --file /foo/bar/tweet.js
You can optionally spare tweets by passing their id_str
, setting a minimum
amount of likes or retweets:
python -m deletetweets --until 2018-01-01 --spare-ids 21235434 23498723 23498723
Spare tweets that have at least 10 likes, or 5 retweets:
python -m deletetweets --until 2018-01-01 --spare-min-likes 10 --spare-min-retweets 5