How to get that inactive Twitter handle you really want

Sean Cann
5 min readJan 19, 2020

…with an insanely simple bot.

You may have seen in the news that Twitter will begin deleting inactive accounts of users who hadn’t logged in within the past 6 months before Dec. 11, 2019.

This is bad news if you happen to be @qwerty123, but great news if — like me — you’ve found the perfect username but some clueless bovine has been accidentally hoarding it for the past 8 years.

An udder tragedy

But wait! 🤚

Before you close this window, open up Twitter to register your dream handle, get distracted by the first tweet in your feed, forget what you came to do, and go down a rabbit hole of political rants for the next 45 minutes, I must reveal something:

We have no idea when Twitter will liberate your aspirational appellation. It could be tomorrow or it could be a year from now.

So that leaves you with 3 options:

  1. Give up on your dreams
  2. Refresh the Twitter page every day until forever to check if it’s free
  3. Write a bot to check for you

If decide to do option 1 or 2, please stop reading this article right now and go read this book instead.

When you decide on option 3, read on…

Making the Bot 🤖

In ~5 minutes, you can have a Google script up and running that checks your dream handle every day and emails you as soon as it becomes available.

Here’s how:

There appear to be three possible states that a Twitter account can be in: active, suspended, or nonexistent.

Since we don’t yet know whether the accounts Twitter deletes will become nonexistent or just suspended, we’ll want to check for both those states.

So we need to handle 3 possible cases:

First, if the account is currently active, we want to check again tomorrow.

Second, if the account is now suspended, we want to get an alert.

Third, if the account is now nonexistent, we also want to get an alert.

With all that in mind…

Let’s automate! 👩‍💻

⚠️ Heads up: As of 12/16/2020, there appears to be an issue with the actual code due to a recent change Twitter made. This may cause your bot to throw false positives. Here is a little more context on the issue, in case you’re feeling generous and want to debug the bot code for me. Otherwise, I’ll update this once it’s solved.

First, let’s create a new Google script. If you’re not familiar, Google Apps Script is a nifty tool that lets you automate the many Google products that you have access to for free if you have a Gmail account.

Go to Google Apps Script homepage and login with your Gmail. Then create a new project.

Next, add this code into your script and change "you@example.com" to be your email, and "oldtwitterhandle" to be the handle you’re seeking:

Explanation: Every time main is executed, this will simply fetch the HTML content for the given Twitter profile. If the response code is not “OK” (200) or “Too Many Requests” (429), the account doesn’t exist. If the fetch succeeds, your bot parses the HTML to check whether “account suspended” is on the page. If the account is nonexistent or suspended, it will shoot you an email.

Now, save the project and try it out! Select the main function and execute it.

You’ll have to approve permissions for your bot to be able to send emails.

It works! Now the last thing to do is make it run automatically.

First, click this clock button to view this project’s triggers.

Since there aren’t any yet, let’s create a new one.

Feel free to configure this trigger however you’d like and then save it. I have mine running once per day, because I noticed Twitter started responding with a 402 Too Many Requests error when I ran it more frequently.

Note that Google imposes a few limits on how much you use their services, but unless you’re using Google Apps Script to hack together a Mr. Robot-scale revolution, it’s incredibly difficult to hit these limits. And if you do happen to be Elliot Alderson — don’t worry, you can just upgrade to a G Suite account.

And you’re done! 🙌

Now kick back and go do something more interesting while your bot is hard at work.

And let’s hope that @jack liberates your dream account someday soon.

⚠️ Disclaimer: The assumptions I’m making ⚠️

  1. That liberated accounts will become available for anyone to claim — sadly, it’s possible Twitter decides to delete old usernames without letting them be reused
  2. That liberated accounts will become either nonexistent or suspended — it’s possible there’s some other purgatory page type that these usernames will go into that your bot isn’t designed to catch

Update as of Nov. 27, 2020 🤷

We still have no idea at what point Twitter will start releasing inactive accounts. Twitter recently announced that it will be holding off on deleting such accounts until it finds a way to memorialize users who have died. I guess the uncertain timeline is all the more reason to let a bot do your work for you.

--

--