david alfonso

Removing all my tweets from X/Twitter

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:

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.

To bypass the second issue, I downloaded a complete account backup file that contains all my tweets as a JavaScript dictionary, including their IDs.

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:

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:

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 ~/.config/systemd/user/twitter-delete.service:


# 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)

# 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


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.

  1. 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. 

  2. 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.