Twitter Eraser

Sep 28, 2020

Time to cleanup my online data. Let’s start with Twitter. Because, why not. It should be easy for me to delete my old tweets, because I am control, right? Of course not 🤭

y u no close ur account

Why not close my Twitter account altogether? First, to limit the risk of identity theft. If I have an active account, I believe it will be easier for me to detect and fight an impersonator, because people who know me on that network can easily warn me, and because my user name has been active for years so you can tell the legitimate and the rogue account apart. Second, for professional visibility reasons, although with Twitter, this can go both ways. And third, I believe that you actually have a better chance to control your "online indentity" if you publish your own curated content, diminishing the risk of an unflattering story about you making first rank on Google.

The joys of the incomplete API

So I am not closing the account at the moment. There must be an option in Twitter that allows me to delete old tweets to my liking, no?

🤣

Of course not. They do not want me or you to remove content from the platform. Some online applications allow you to do that. But I’m trying to regain control on my data. Giving access to it to a third party seems backward. Plus, I’m a nerd. There is a Twitter API I can use to do the job. Sure I can hack something in no time. Yes, there is an API. But it is disappointing.

First, you must request access to it, and give an explanation on what you intend to do with it. I suppose this leaves them the option to deny your request if you are building a competing service. It is legitimate, but in the end, your are dependant on their arbirary decision. So here I go, explaining honestly what I intend to do. Request granted. Cool. Now I have the privilege to use their API.

(Un)surprisingly, there is no GET operation on /tweets to retrieve your own tweets. I can understrand Twitter would not expose such endpoint to retrieve all the tweets in the universe. But to retrieve my own tweets? What would the issue be?

Using the quirky v. 1.1 API (you can tell they did not know what REST was when they designed it - some help here), you can delete a tweet. But you must know its identifier. And you can’t get a list your tweets and their IDs with the API. This is going to be tricky. 🤔

Instead, you can download an archive of all your data. It comes with a chilling effect: expect a 24-48h delay for them to build an archive with 3000+ tweets. As if they could not handle the load. But I am not giving up my plan so easily. I waited. I paid off.

The archive contains JSON files you can easily parse. Sample:

"tweet" : {
    "retweeted" : false,
    "source" : "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
    "entities" : {
      "hashtags" : [ ],
      "symbols" : [ ],
      "user_mentions" : [ {
        "name" : "ploum.net",
        "screen_name" : "ploum",
        "indices" : [ "3", "9" ],
        "id_str" : "781660",
        "id" : "781660"
      } ],
      "urls" : [ ]
    },
    "display_text_range" : [ "0", "140" ],
    "favorite_count" : "0",
    "id_str" : "257572918735810562",
    "truncated" : false,
    "retweet_count" : "0",
    "id" : "257572918735810562",
    "created_at" : "Sun Oct 14 20:05:43 +0000 2012",
    "favorited" : false,
    "full_text" : "RT @ploum: It's official: we missed 14 votes to have the first belgian pirate elected in Ottignies-Louvain-la-Neuve, a city of 30,000 in ...",
    "lang" : "en"
  }

Then, leveraging this neat little repository that relies on the archive you downloaded, you can proceed with mass deletion. Setup your credentials as explained, then for instance:

$ delete-tweets --until 2020-06-01 tweet.js
...
Number of deleted tweets: 3562

Off they go! Thousands of tweets deleted in a few minutes. ✨ Now I feel cleaner ✨

Who’s in control?

Make no mistake. This process, while within reach for the initiate, is not accessible to everyone. Even so, I had to assess several options, request access to the API, wait for the archive, read the doc, search for a library that would work. With Twitter, Facebook and the like, we are never really in control.

Sharing is caring!