How To Delete All Your Tweets

There may come a time in your Twitter existence when you realize that you’ve said a lot of dumb stuff in your past. Facebook is especially good at reminding you of how immature and annoying you were 10 years ago. So while the reasons may differ from person to person, it’s important to know how to flush your Twitter account.

Unfortunately, Twitter doesn’t make this easy. And the 3rd party online tools have some severe limitations: 1) the Twitter API only exposes a limited number (few thousand) of your most recent tweets, and 2) you’re giving a 3rd party tool all permissions to your account.

Well, if you have a few minutes and have Ruby installed, you can do this whole process by yourself.

Create an Oauth App

Head over to: https://developer.twitter.com/en/apps If you already have an existing Oauth app, you’re good to go. If you need to create one, you’ll need to sign up for a Twitter developer account.

Once you create (or have) an Oauth app handy, view the app details and click on “Keys and Tokens”. You’ll need 4 pieces of data:

  1. Consumer Key
  2. Consumer Secret
  3. Access Token
  4. Access Secret

You may need to generate the Access Token. You can do this by clicking “Create” under “Access token & access token secret”.

Hang onto this info – you’ll need it in the Ruby script later.

Download Your Data

Because Twitter doesn’t expose all of your tweets in the API, you’ll need to get all of the IDs yourself. Luckily, Twitter allows you to download all of your Twitter data.

  1. Head to: https://twitter.com/settings/your_twitter_data
  2. Under “Download your Twitter data”, click “Request Data”

Give it a few minutes and you’ll get a link to download a ZIP file. Inside this, you’ll want to grab two specific files:

  1. tweets.js (this will give you all your tweet ID’s), and
  2. like.js (this will give you the tweet ID’s of your likes)

Do two things to these files:

  1. Remove window.YTD.like.part0 = from the first line. Now it should only be [ {
  2. Save the file to your desktop (or somewhere you can find it easily) and rename the file extension to .json

Delete Your Tweets

Ok. You ready? No turning back, my friend.

Create a file in the same directory as your two JSON files. Call it … twitter.rb ?

require "twitter"
require "json"

client = Twitter::Streaming::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

tweets = JSON.parse(File.read('tweets.json'))
tweets.each do |tweet|
  begin
    client.destroy_tweet(tweet["id"])
    print "."
  rescue => exception
    puts "\n>> #{exception.message}"
  end
end

To run this, simply open a terminal window and run ruby twitter.rb.

Common issues:

  1. Unauthorized. Your keys are wrong. (I accidentally had a space after my access token)
  2. Random other twitter messages exposed in exception.message. (I have about 40 @-replies directed at suspended accounts. Twitter won’t show them, but they also won’t let me delete them)

Delete Your Likes

Done with your tweets? Let’s get rid of those likes too. Change your twitter.rb file to this:

require "twitter"
require "json"

client = Twitter::Streaming::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

likes = JSON.parse(File.read('like.json'))
likes.each do |like|
  begin
    client.unfavorite like["like"]["tweetId"]
    print "."
  rescue => exception
    puts "\n>> #{exception.message}"
  end
end

Same running process: ruby twitter.rb.

Conclusion

The hardest part of this is creating the Oauth app. I had some old apps from back in the day that I was able to repurpose. Just remember: you can’t put these tweets back. So give it a second thought before you run these scripts.

Happy Twittering!

Hi there, I'm Jon.

Writer. Musician. Adventurer. Nerd.

Husband. Dad to three. From: all over the place.

Exvangelical, but still amazed. Enneagram 7.