Cat Twitter

“if you’ve done this kind of thing before”

If you’re just looking for code, check out my GitHub repo. It's written in node. If you’re here to read a blog post, feel free to skip to the next section.

My general process was to:

  • Apply for a developer account
  • Apply to create an application
  • Download all of my twitter data as a personal back-up
  • Use twit make an API call for my user timeline
    • Pull the tweet ID off of each object in the response data
    • Use twit to make an API call to delete each tweet with that ID

The only parts of this I had difficulty with were:

  • Understanding Twitter's authentication process
  • Dealing with rate limits set on Twitter's  standard API

If you use a library like twit, authentication will be handled for you. Initially, I tried not to use any third-party packages. Authentication isn’t that difficult — it’s just a matter of “picking your battles.”

I believe calls to Twitter’s standard API that delete a tweet are rated limited at 300 per 3 hours. My script just runs until you get an error. I would just run it again after 3 hours.

 The Narrative

Twitter doesn’t provide a solution to bulk-delete tweets. They actually state:

If you're looking to get a fresh start on your Twitter account without losing your username, the best way to do this is to create another account with a temporary username, and then switch the username between your current account and the new account. Please see our article on changing your username for more info.

Still, there are many third-party services you can find to delete all of your tweets. The decision to do it myself was less about a lack of trust in these services, and more about a natural curiosity of the process. It sounded like a fun project. I also kind of dislike the company of Twitter, and I felt like if I could help others delete all their tweets that I would be contributing to “sticking it” to the various abstractions that Twitter represents in my mind.

My initial goal was to provide a free and simple code snippet with no third-party packages or dependencies that could delete all the tweets of a given account. I had a vision in my mind of someone who didn’t know how to code reading through my script and thinking, “Oh, I see what’s going on. I trust this. I’ll use it.” I gave up on this vision pretty quickly.

If you want to delete all your tweets yourself via the API, and you don’t know how to code, you’d need to do at least all the following things:

  • Choose and install a programming language
  • Install git to clone my repo
  • Open a terminal, navigate directories, and clone the repo
  • Sign up for a developer account on Twitter
  • Apply to create an application and understand which fields actually needed to be completed
  • Find things called an “access token secret” and “secret API key” for your application and still feel comfortable
  • Read through the code I wrote and for some reason trust it more than the code written by someone else you don’t know on the internet

In addition to losing faith that I could create something more trustworthy than what already exists in the world, I lost interest trying to create a dependency-free script. I found Twitter’s documentation on authentication to be somewhat confusing, and turned to twit to just handle it for me. I went through a similar process as in the video below. I don’t really think that the authentication flow is all that difficult to grasp. I just didn’t want to spend a lot of time on the matter once I felt like I wasn’t writing something for non-coders to look at.

And once I installed twit, my resistance to third-party modules completely broke down. I decided to install and use RxJS just for the fun of it.

The first time I ran the script, several hundred tweets were deleted, and then the program exited with a status of 403  and a message of, "User has been suspended." I started searching Google in a panic, but realized this must be related to rate limiting and happen all the time. Twitter has separate error codes for rate limiting, but I just waited a while, reran the script, and never saw that specific error again.

I also tried using my downloaded data from Twitter as a source of tweet ID’s instead of making an API call to get my timeline. I quickly realized this made the process more complicated, as I then needed to assume responsibility of tracking which tweet ID’s had been deleted.

Ultimately, I felt disappointed when I ran my script and realized all my tweets were deleted. I had enjoyed the process of running the script, hitting an error, and tinkering to fix it — or otherwise just trying to optimize the script. I do feel proud when I visit my Twitter profile and just see suggestions of other people to follow and a “Show more” button.