I want to remove all my tweets. It's been too many years since I've used Twitter, either as a reader or as a writer, and it's about time to leave for good 1 2. This post explains the steps I've done to achieve it.
The API is useless, long live the API
The free Twitter API tier has been super restrictive since a few months ago. Some developers (who don't make money with it) have started dropping support.
OK, but what about my use case? It turns out I can still delete (and post) tweets! But wait, there are some caveats:
- Rate-limit: 50 api requests/day, which is a bit too scarce.
- Unknown tweet IDs: No free endpoint available to list your own tweets and get their ID, which is needed to delete them.
The first issue is a matter of abiding by the limits and deleting just 50 tweets per day. I can live with that, but if you have tweets in the order of thousands, you will need some patience. For example, for 10.000 tweets, you'd need 200 days to delete them all :O Maybe you'd be better off deleting your account.
Create a new app in the Twitter Developer Portal
To be able to authenticate yourself in the Twitter API, you need to have a project app created in the Developer Portal.
The first time I filled out the request, I never got a response (was it denied? I don't know). The second time, I tried to explain the intent of the app with more detail. Somehow, it quickly got accepted.
Once I had the app, I needed to generate the following keys and tokens required for OAuth 1 authentication:
- Consumer keys: These identify your app so that the API knows what app is doing the request.
- Access token and secret: These are user-specific credentials, which is perfect because we want to delete our tweets.
Delete 50 tweets per day
I implemented a Python script that issues a
DELETE method request to the
/2/tweets API endpoint up to 50 times, using the backup file as the source of Tweet IDs.
The script has the following features:
- It receives one command-line argument: the path to the Twitter backup (unzipped).
- It reads credentials from environment variables.
- Tweets are deleted sequentially in the order they appear in
data/tweets.jsinside the backup.
- The number of deleted tweets is stored in
~/.twitter-delete-all-start-positionto continue where it left it.
- Use the position file as a marker filer to wait at least 24 hours after its last modification time.
Running the script daily
Given the features and requirements of the script, I want it to run whenever I turn on my computer. Because the script won't call the API unless at least 24 hours have passed since the last time, we can run it multiple times each day without hitting the rate limit.
I'm using Ubuntu 22.04, so I'll go with Systemd as the mechanism to run the script.
First, create the user service file
[Service] Type=oneshot RemainAfterExit=true StandardOutput=journal # Define DISPLAY for desktop notifications and remember to provide # all the tokens (you might want to use a more secure alternative # if you have the need for it) Environment=DISPLAY=':0' CONSUMER_KEY= CONSUMER_SECRET= ACCESS_TOKEN= ACCESS_TOKEN_SECRET= # I use pyenv to manage my virtual envs and have one named `scripts` # just for my scripts. ExecStart=%h/.pyenv/versions/scripts/bin/python3 %h/scripts/twitter-delete-all.py %h/backups/twitter-2023-10-18.zip [Install] WantedBy=default.target
Finally, enable the service and restart the computer to make sure it's working:
$ systemctl --user enable twitter-delete.service
Now, every time my computer is on, the script will run in the background, sleep if necessary, and delete up to 50 tweets of my account.
Well, I'm not going to completely delete my account (for now) as it would be quickly taken by someone that could impersonate me or just be confusing to people that knows me. ↩
It is known that xAI uses all tweets in Twitter to train its new chatbot and when a tweet is deleted it's actually soft deleted, so it remains in Twitter servers. In fact, they are part of the backup archive. In any case, could deleting my Twitter account stop xAI from using my tweets? Most certainly no. ↩