Skip to content

Instantly share code, notes, and snippets.

@keekerdc
Last active December 27, 2019 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keekerdc/b8a67627cba331f2a677031ccb0c0061 to your computer and use it in GitHub Desktop.
Save keekerdc/b8a67627cba331f2a677031ccb0c0061 to your computer and use it in GitHub Desktop.
Nuking your twitter without deleting the account, with ruby and t

This approach requires a proper shell, a working Ruby installation, and some basic unix programs like grep and tr. If we're already in too deep for you, bribe a friendly nerd with some food or something to help you; walking you through setup of these things, especially if you're on Windows, will probably result in more frustration than it's worth, and is way outside the scope here. This can be time consuming, but it's not terribly technically challenging, so preferrably find someone you like, because you're going to be hanging out a bit.

The good news is this approach is far less time consuming than trying to do this through any other client; the web app in particular requires three clicks per tweet, constant scrolling, and makes it impossible to delete RTs made before the Aug 2015 syntax switch. It's still going to take you a while, especially if you've pushed up over 10k or 20k tweets; more than that and this will still likely be a multi-day project. Due to limitations of the Twitter API, and some foibles of the platform that are tuned to make the primary function - sucking in and displaying recent content - work quickly and reliably, this process of scrubbing your timeline without dropping the entire account is decidedly outside 'in-scope' use cases for Twitter.

  1. Make sure you have a reasonably current version of Ruby ready to roll and loaded as active. 2.3.1 is groovy at time of writing.
  2. Globally install the t gem: gem install t. A bit of docs are here, but the prompt help is pretty comprehensive.
  3. t authorize and follow the steps there.
  4. Once authorized, do a quick t timeline keekerdc but instead of my username (keekerdc), use yours. You should see your last 20 tweets. This is just to verify everything's hooked up.
  5. Time to begin. Here's the main command of this process - again, replace my username (keekerdc) with yours : t delete status $(t timeline keekerdc -l -n 3200 | grep -Eo '^\s*[^ ]+' | tr '\n' ' ')
    • It looks up the last 3200 tweets (Twitters basic limit) and lists them with the IDs
    • It scrapes those IDs from the list
    • It puts them all in a string
    • It feeds that long ID string to the delete status command
  6. Now you'll be prompted for each tweet: "Are you sure..." Type y and Return. This is monotonous, so put a podcast on, or something.
  7. Rinse and repeat until you've scrubbed your feed clean.
  8. There may be a point where you run the command in point #5, and it spits back this, even though you look on your profile and there's still a large number of tweets reported: ERROR: "t status" was called with no arguments Usage: "t status TWEET_ID [TWEET_ID...]" Best I can tell is that group of 3200 most recent tweets is cached rather agressively, and so while all the tweets are gone because you've deleted them, the cache is still reporting "no, really, these are the IDs." Only thing to do is wait it out; eventually (sometimes hours later), things expire and you'll have a fresh batch to begin ripping through again.
  9. If after 24 hours of waiting, you have tweets that aren't bubbling back up to the top of your timeline, other measures might be necessary. I hit about around mid-2013 where I still had a good 9k tweets that weren't being coughed up. The only way I've found to retrieve those tweets are through the search.twitter.com interface, and by going month-by-month.
    • Head over to search.twitter.com.
    • Hit the link underneath the simple search form for 'advanced search'.
    • In the 'from these accounts' field, put your username. Then select a one-month maximum date range where you think you'll find tweets. I've preferred to go from most recent towards the oldest tweets; so I started 2013-08-01 to 2013-09-01. Run the query.
    • On the results page, use the 'Latest' tab. Scroll and scroll and scroll until you've reached the end of the date range.
    • Open a developer console and use the following bit of javascript to get the list of tweet IDs in the format you need to use with the t utility: $('[data-tweet-id]').map(function(){return $(this).attr('data-tweet-id');}).get().join(' ')
    • Copy what returns and run the delete command with it: t delete status [tweet id list here without brackets]
    • Follow the same process as in step 6 until you've worked through that block of tweets.
    • Refresh the results page for good measure; I've found I typically get a good three or four rogue tweets that for whatever reason didn't show up in the original list. Delete those with the same process.
    • Bump the months starting/ending back by one on your search query and repeat until you reach the end.
  10. Even the extreme measures of step 9 may not be enough. I hit a point where my tweet count was still 1000+, but I couldn't get them to appear no matter how I rubbed the API. Time and patience is the only way to go here, every several days I checked back up on my public timeline, and another 200 tweets or so would get barfed up out of the furthest reaches of the system, at which point I could run step 5 again and clear them out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment