Delete all tweets and retweets from your account or delete all tweets posted before the last X days.
The script reads the twitter file and deletes one by one starting with the oldest tweet. It is possible to set a number of days (MAX_AGE_IN_DAYS) for which there are no more tweets, for example: if MAX_AGE_IN_DAYS = 30, the script will not delete the tweets published in the last 30 days. It is also possible to define a specific ID that we do not want to eliminate, for example, if we put the ID of our first tweet in the SAVE_THIS_TWEET variable, it will not be deleted.
Google Apps Script has a limitation on the script runtime of 6 min, so it is advisable to schedule a script execution automatically every 15 minutes so as not to exceed the limits of the Twitter API requests. (Running the script every 10 minutes 6,000 tweets per hour are deleted.)
Get your Twitter archive
- Open your account page.
- Click 'Your Twitter archive', and a link to your archive will arrive per email.
- Follow the link in the email to download the archive.
- Unpack the archive.
Create new twitter app and configure API
- Open Twitter's Application Management, and create a new Twitter app.
- Set the permissions of your app to Read and Write.
- Set the required environment variables
Create new Google Apps Script project Google Apps Script
Copy deleteTweets.gs file in you GAS project and configure variables
Copy your TWEET.JS file from twiiter archive to your Google Drive and save the file ID
Execute script and enjoy your life
Configure the following variables:
var TWITTER_USER = 'YOUR TWITTER USER NAME';
var MAX_AGE_IN_DAYS = 30;
var SAVE_THIS_TWEET = 0;
var CONSUMER_KEY = 'YOUR CONSUMER KEY';
var CONSUMER_SECRET = 'YOUR CONSUMER CONSUMER_SECRET';
var ACCESS_TOKEN = 'YOUR ACCESS TOKEN';
var ACCESS_SECRET = 'YOUR ACCESS SECRET';
var TWEET_JS_FILE = 'TWEET.JS FILE ID SAVED IN YOUR GOOGLE DRIVE';
variable | description |
---|---|
TWITTER_USER | Twitter username (exclude @) |
MAX_AGE_IN_DAYS | tweets with a date greater than this number, will be deleted |
SAVE_THIS_TWEET | this ID won't be deleted |
CONSUMER_KEY | The Consumer Key from your Twitter App |
CONSUMER_SECRET | The Consumer Secret from your Twitter App |
ACCESS_TOKEN | The Access Token from your Twitter App |
ACCESS_SECRET | The Access Secret from your Twitter App |
TWEETS_JS_FILE | ID from tweet.js file in your Google Drive |
1.1.0
See the LICENSE file for license rights and limitations (GPL-3).