How to Delete all your Tweets from Twitter (X) as quickly as possible?

How to Delete all your Tweets from Twitter (X) as quickly as possible?

With the rise of Musk (and the fall of Twitter) an individual might be interested in removing all of their old Tweets, without simply deactivating their account permanently on the platform. In my case I had over thirty thousand tweets in the past 15 years that I felt like I wanted to remove, but I don’t want to give up the account itself.

How do you bulk delete tweets on Twitter (x)?

I started by looking for a way to do this on Twitter itself, but I was unable to find one. Twitter (x) offers the ability to delete individual messages, but not bulk. It would take me a couple of years (I get distracted easily) to likely to through and manually delete every message I ever sent. Since I couldn’t find a way to bulk delete tweets on Twitter, I started looking at Third Party services that offered the ability to delete tweets. I discovered a few that offered ways to delete tweets, but they were limited in how many tweets they could remove. I think the best I found was able to remove around three thousand tweets in 30 days, at a cost.

I wasn’t interested in paying a monthly fee to someone to delete tweets, especially over 10+ months to remove them all, so I decided to figure out how to do it myself, or rather:

Can you get ChatGPT to write an application to delete Tweets?

I reached out to my good buddy ChatGPT, which earlier this summer helped me write a web application that runs on Azure to take an uploaded photo and add an event mark to the photo (check out PhotoMark.co).

I was able to quickly and easily prompt ChatGPT to help me create an application that I could plug into the Twitter (x) API to delete tweets. What we came up with was a simple windows console application written in C# that allows you to utilize your Twitter API Keys (how to sign up for those below) to run through a list of your Tweet IDs (you need your Twitter Archive, see how to generate that below).

Let me introduce you to DeleteX!

In order for this all to work you need to do a few things:

  1. Export your Twitter Data Archive (this can take 24 hours, so go ahead and do this first)
  2. Create a Twitter Developer account at https://developers.twitter.com/
  3. Clone the Git Repository (link to repo)
  4. Modify the Program (populate your API keys)
  5. Run the Program

Download your Twitter Archive

This process may take you the longest, because you are dependent upon Twitter (x) to export your data archive, and that can take 24 hours to generate. To get started login to your Twitter profile then go to the Settings. Under the Your Account section find the Download an archive of your data

1

In order to generate your archive it will likely prompt you to enter your password and also send a pin code via email or SMS to validate that you are you. After jumping through those hoops you will be able to request the archive. Then you wait, up to 24 hours, while Twitter (x) generates the files, once they are complete they will email you and you should be able to find a download link in the same area of your profile. The download of the archive is potentially huge, depending on the size of your Twitter account. At 30k tweets my download was 545mb.

Once you have the archive (zip) file downloaded, you will need to extract the contents of the Zip file. The archive is a mini standalone version of Twitter that can run in a browser for you to navigate through your timeline. It is actually pretty nifty, but what we need for this process is to get access to the data for the tweets themselves, to do that you will need to copy the tweets.js file from the DATA folder. You’ll do this later in the process. We’re going to use that file along with a Powershell script in the repository to generate the list needed for the API calls.

Create your own Twitter Developer Account (API keys)

While you are waiting for your Twitter archive to generate go ahead and setup a developer account in order to get an API Key that you can leverage for the application.

  • Navigate to Developer.twitter.com
  • Click on “Sign Up For Free Account”, there’s no need to give Elon any $$ for this.
  • You’ll need to provide a description of your usage of the Twitter API. It requires 250 characters, here’s an example.
    • I will be building a custom twitter application that will assist me with managing my Twitter account. Utilizing the Free API will be sufficient for what I am trying to do with my account. I do not need to "Read" tweets, only post or remove tweets from my account in a somewhat automated fashion.
  • Be sure to read/review/understand the Developer Agreement and Developer Policy
  • Navigate to the Projects/Default Project section on the left side of the page
  • On the Settings tab for the project, you can customize the Application name.
    • Click on the “Set up” button under “User authentication settings”, here we need to define that our application will have read/write permissions
    • 2
    • You will also need to provide a Callback URI/Redirect URL and Website URL for the application. Use whatever URLs you have access to on your side, the application provided doesn’t actually make any calls to these.
    • After you click save you’ll be presented with OAuth 2.0 Client ID/Secret, you can discard these, we won’t be using them for our DeleteX application.
  • Click on Keys and Tokens tab of the project page, then click on Generate/Regenerate under the Consumer Keys section, this will allow you to create the API Key and API Key Secret that you’re going to need later in this process. Save these somewhere in a text file on your computer.
    • Once you click “Yes I Saved Them” you won’t be able to see them again, but you can always regenerate if needed. Protect these though, they are not something you should share with anyone else.
    • THESE KEYS CONTROL YOUR TWITTER ACCOUNT. Be careful with them, don't check them into a public source control system.
  • Click on Generate in the Access Token and Secret section
    • Click on Generate/Regenerate to create an Access Token and Secret, again save these into the same Text file as the Consumer Keys so that you can leverage them later. If you failed to perform the OAuth 2.0 configuration before creating the Access Token/Secret, you’ll need to regenerate those tokens after setting up OAuth 2.0 so that you get the proper read/write permissions configured.
    • THESE KEYS CONTROL YOUR TWITTER ACCOUNT. Be careful with them, don't check them into a public source control system.

Clone the Repository

For this DeleteX Application we’ve provided a Github Repository that has the source code necessary to delete your Tweets from Twitter (x). You’ll need to download the Repository through your method of choice, I will document the steps here using Git For Windows.

  • Click Start/Run and type GIT BASH to load the git bash app/console
  • Navigate to the location where you want to clone this repository (I will use g:\projects)
    • cd g:
    • cd projects
  • Clone the repository
  • This should create a folder with the path g:\projects\DeleteX that contains the repository

 

Copy tweets.js file and generate tweets.csv

In the Twitter Archive process earlier we pointed out the tweets.js file, you need to copy this file from the /data/ folder of your archive into the root of the DeleteX project.

image

Inside of the repository is a Powershell script that will take the tweets.js file and generate a tweets.csv file with a list of all the TweetIDs. In a Powershell console, or in the Console in VS Code you will need to execute the Powershell script

You can execute the Powershell script with the following command:

.\exporttweets.ps1

image

If when you try to run the script you get an error about executing scripts you might need to run this command, I ended up running this command via “Run As Administrator” from the Powershell prompt in Windows. Please read up on Powershell script security before doing this.

set-executionpolicy remotesigned

Modify the Application

In order to run the application you need to modify the Program.cs file to provide the API Key/Secret and the Access Token/Secrets. If you have Visual Studio Professional installed, you can open up the DeleteX.sln file in the directory created above. If you don’t have Visual Studio Pro, I recommend that you utilizing Visual Studio Code which is available for free. Open up the DeleteX folder in VS Code

  • Using VS Code you can open up the Program.CS file in the projects/DeleteX directory, you’re going to Edit the following variables
    • twitterApiKey
    • twitterApiKeySecret
    • accessToken
    • accessTokenSecret
    • image

 

Run the Application to Delete Tweets

In the Terminal in VS Code you can make sure that the LinqToTwitter library is installed with this command:

dotnet add package LinqToTwitter

Running the application is even easier than that, also in the Terminal, simply type:

dotnet run

When you do that the application should start up, it will take 15 seconds before it runs through the first attempted tweet deletion. From there it should process through your list of Tweets, logging which ones get deleted so that if you have to stop/restart the process, it will not attempt to remove those.

 

Future Enhancements

What will this script bring in the future? Most likely nothing, but if you feel like adding to it, feel free to clonse and submit a Pull Request on GitHub if you have any cool enhancements to it.

If you want to speed up the process, you can change the timer values. I started originally with it running every 30 seconds with concerns that Twitter might have a problem with the number of requests, after letting it run for 12 hours I decided I would up the speed to every 15 seconds, from there I actually increased it to every 5 seconds… I was able to burn through my 30k tweets over about a 48 hours period. You definitely run the risk of running into Rate Limit violations, so be careful with what you do.

 

Feedback?

If you have any feedback, feel free to post here in the comments!

Recent Comments

There are currently no comments. Be the first to make a comment.

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.