Skip to content

Instantly share code, notes, and snippets.

@apsun
Last active September 10, 2023 05:06
Show Gist options
  • Save apsun/d5a16275d7078c9c038b877adf292f28 to your computer and use it in GitHub Desktop.
Save apsun/d5a16275d7078c9c038b877adf292f28 to your computer and use it in GitHub Desktop.
Delete your old tweets with this disgusting bash script

100% free. Runs completely locally on your machine. Bypasses the 3200 tweet limit. May require some eye bleach for the script. Here's how to use it:

  1. Go to settings -> account -> your Twitter data and request a download. This may take a few hours. You'll get an email with a link to download a zip file. Extract the zip file and navigate to the data directory.

  2. Go to Twitter in a web browser and find any Tweet you want to delete. We're going to use it to extract your authentication credentials for the next step. Open developer tools, delete the tweet, and find the request to https://twitter.com/i/api/graphql/.../DeleteTweet. Right click it and copy it as cURL.

  3. Save delet_tweets.sh into your data directory. Open it in a text editor, and paste the command you got from the previous step where it says YOUR_CURL_COMMAND_HERE. Replace the id parameter for --data with $tweet_id (make sure to adjust quoting accordingly). Add --compressed as well to tell curl to un-gzip the response.

  4. Let 'er rip. It will probably take a while (for me, somewhere around 10-20k tweets an hour), so leave it running in the background. If you want to see your deleted tweets as they go by, pipe the output of curl to jq -r .full_text (add -s to curl too).

#!/bin/bash
DELETE_BEFORE="2020-03-04 15:45"
cat tweets.js \
| sed '1 s/window.YTD.tweets.part0 = //' \
| jq -r '.[] | [.tweet.id, (.tweet.created_at | strptime("%a %b %d %H:%M:%S %z %Y") | mktime)] | @tsv' \
| sort -k2 -n \
| awk -v d="$(date --date "$DELETE_BEFORE" +%s)" '$2 < d { print $1 }' \
| while read tweet_id; do
YOUR_CURL_COMMAND_HERE
done
@heiner
Copy link

heiner commented Jul 25, 2022

The delete requests these days seem to be for https://twitter.com/i/api/graphql/$queryId/DeleteTweet, and the curl command includes a line like --data-raw "{\"variables\":{\"tweet_id\":$tweet_id,\"dark_request\":false},\"queryId\":\"$queryId\"}". Also, there's rate limits which make it a bit more convenient to restrict the date range both ways:

#!/bin/bash

set -euo pipefail

DELETE_AFTER="2022-06-01 0:00"
DELETE_BEFORE="2022-07-01 0:00"

echo "deleting everything after ${DELETE_AFTER} = $(gdate --date "$DELETE_AFTER" +%s)"
echo "deleting everything before ${DELETE_BEFORE} = $(gdate --date "$DELETE_BEFORE" +%s)"


cat tweet.js \
| sed '1 s/window.YTD.tweet.part0 = //' \
| jq -r '.[] | [.tweet.id, (.tweet.created_at | strptime("%a %b %d %H:%M:%S %z %Y") | mktime)] | @tsv' \
| sort -k2 -n \
| awk -v d="$(gdate --date "$DELETE_AFTER" +%s)" '$2 > d' \
| awk -v d="$(gdate --date "$DELETE_BEFORE" +%s)" '$2 < d' \
| awk '{ print $1 }' \
| while read tweet_id; ...

(gdate is brew-speak for GNU date on MacOS.)

@Faraon366
Copy link

How is this parameter calculated graphql/id?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment