Delete tweets
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.
Prerequisites
Unfortunately, as of late 2018, you are required to have a Twitter Developer account in order to create a Twitter app.
Apply for a Twitter Developer account
- 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.
Create a Twitter app
- 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.
Configure your environment
- 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. Assuming you are using Bash:
$HISTCONTROL
to be set
to ignorespace
or ignoreboth
).
export TWITTER_CONSUMER_KEY="[your consumer key]"
export TWITTER_CONSUMER_SECRET="[your consumer secret]"
export TWITTER_ACCESS_TOKEN="[your access token]"
export TWITTER_ACCESS_TOKEN_SECRET="[your access token secret]"
Get your tweet archive
- 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, and move
tweet.js
to the same directory as this script.
Getting started
Local
First, install the required dependencies.
pip install -r requirements.txt
Then, for example, delete any tweet from before January 1, 2018:
python deletetweets.py -d 2018-01-01 tweet.js
Or only delete all retweets:
python deletetweets.py -r retweet tweet.js
Docker
Alternatively, you could run this script in a Docker container.
First, you need to build the Docker image.
docker build -t koenrh/delete-tweets .
Then, run the script using the following command.
$HISTCONTROL
to be set
to ignorespace
or ignoreboth
).
docker run --env TWITTER_CONSUMER_KEY="$TWITTER_CONSUMER_KEY=" \
--env TWITTER_CONSUMER_SECRET="$TWITTER_CONSUMER_SECRET=" \
--env TWITTER_ACCESS_TOKEN="$TWITTER_ACCESS_TOKEN=" \
--env TWITTER_ACCESS_TOKEN_SECRET="$TWITTER_ACCESS_TOKEN_SECRET=" \
--volume "$PWD:/app" --rm -it koenrh/delete-tweets -d 2018-01-01 /app/tweet.js
You could make this command more easily accessible by putting it an executable,
and make sure that it is available in your $PATH
.