Skip to content

Instantly share code, notes, and snippets.

@ranemirusG
Last active July 13, 2023 14:55
Show Gist options
  • Save ranemirusG/3bf999541a63d448ed393046e4ffc32f to your computer and use it in GitHub Desktop.
Save ranemirusG/3bf999541a63d448ed393046e4ffc32f to your computer and use it in GitHub Desktop.

ELIMINA TWEETS ANTIGUOS

1 Solicita la descarga de tus datos de Twitter. Ve a "Configuración" -> "Cuenta" -> "Tus datos de Twitter" (Puede tomar hasta 24 horas (o más) para que Twitter prepare tus datos para la descarga. Así que hay que esperar)

2 Una vez que tus datos estén listos, recibirás un correo electrónico con un enlace para descargar un archivo zip. Extrae el archivo zip y ve al directorio "data" para acceder a tus datos de Twitter.

3 Inicia sesión en Twitter usando el navegador Brave, Chrome o Edge y encuentra cualquier tweet que desees eliminar. Lo vamos a usar para extraer tus credenciales de autenticación para el siguiente paso. Así que:

3.1) Abre las herramientas de desarrollo (F12) y selecciona la pestaña "Red". 3.2) Elimina el tweet como lo harías normalmente. 3.3) Escribe "delete" en el filtro de herramientas de desarrollo. Te mostrará una solicitud llamada DeleteTweet (https://twitter.com/i/api/graphql/.../DeleteTweet). 3.4) Haz clic derecho en ella y selecciona "Copiar" -> "Copiar como PowerShell".

4 Guarda borrar_tweets.ps1 en tu directorio "data". Ábrelo en un editor de texto. Ve a la línea donde dice PEGAR DEBAJO DE ESTA LINEA y pega lo que copiaste en el paso 3.4.

5 Ahora debemos hacer dos reemplazos en lo que acabamos de pegar. En ambos casos hay que reemplazar el numero de ID (NUMERO) por la variable $tweetId

Deberias ver algo asi:

5.1)

"referer"="https://twitter.com/yourTwitterUser/status/NUMERO"

por

"referer"="https://twitter.com/yourTwitterUser/status/$tweetId

5.2)

"variables`":{`"tweet_id`":`"NUMERO`",`"dark_request`":false},`"queryId`":`"VaenaVgh5q5ih7kvyVjgtg`"}"

por

"variables`":{`"tweet_id`":`"${tweetId}`",`"dark_request`":false},`"queryId`":`"VaenaVgh5q5ih7kvyVjgtg`"}"

6 Abre PowerShell como administrador en el directorio "data" y ejecuta el script.


DELETE OLD TWEETS

  1. Request a download of your Twitter data. Go to "Settings" -> "Account" -> "Your Twitter Data". It may take up to 24 hours (or more) for Twitter to prepare your data for download. So, we have to wait.

  2. Once your data is ready, you will receive an email with a link to download a zip file. Extract the zip file and go to the "data" directory to access your Twitter data.

  3. Login to Twitter using Brave, Chrome or Edge browser and find any Tweet you want to delete. We're going to use it to extract your authentication credentials for the next step. So:

    3.1) Open developer tools (F12) and set the network tab. 3.2) Delete the tweet as you would normally do it. 3.3) In the developer tools filter, write "delete". It will show you a request called "DeleteTweet" (https://twitter.com/i/api/graphql/.../DeleteTweet). 3.4) Right-click it and select "Copy" -> "Copy as PowerShell".

  4. Save borrar_tweets.ps1 into your "data" directory. Open it in a text editor. Go to the line where it says PASTE BELOW THIS LINE and paste what you have copied in step 3.4.

5 Now we need to make two replacements in what we just pasted. In both cases, we need to replace the ID number (NUMBER) with the $tweetId variable It should be something like:

5.1)

"referer"="https://twitter.com/yourTwitterUser/status/NUMBER"

to

"referer"="https://twitter.com/yourTwitterUser/status/$tweetId

5.2)

"variables`":{`"tweet_id`":`"NUMBER`",`"dark_request`":false},`"queryId`":`"VaenaVgh5q5ih7kvyVjgtg`"}"

to

"variables`":{`"tweet_id`":`"${tweetId}`",`"dark_request`":false},`"queryId`":`"VaenaVgh5q5ih7kvyVjgtg`"}"

  1. Open PowerShell as an Administrator in the data directory and run the script.
# ELIMINAR TWEETS ANTERIORES A LA FECHA SELECCIONADA
# DELETE TWEETS PRIOR TO SELECTED DATE
# Obtener el contenido del archivo tweets.js y convertirlo en un objeto de PowerShell
# Get the content from the tweets.js file and convert it to a PowerShell object
$content = Get-Content -Path 'tweets.js' -Raw | Select-String -Pattern 'window.YTD.tweets.part0 =' | ForEach-Object { $_ -replace 'window.YTD.tweets.part0 =', '' } | ConvertFrom-Json
# Solicitar al usuario que ingrese una fecha en el formato dd-mm-yyyy (Ejemplo: 29-04-2019)
# Prompt the user to input a date in the format dd-mm-yyyy (Example: 29-04-2019)
$dateString = Read-Host "Enter a date (dd-mm-yyyy)"
# Convertir la cadena de fecha en un objeto DateTime
# Convert the date string to a DateTime object
$date = [DateTime]::ParseExact($dateString, "dd-MM-yyyy", $null)
# Filtrar
# Filter
$tweetsToDelete = @()
foreach ($tweet in $content) {
$tweetDateString = $tweet.tweet.created_at
$tweetDate = [DateTime]::ParseExact($tweetDateString, "ddd MMM dd HH:mm:ss zzzz yyyy", $null)
if ($tweetDate -lt $date) {
$tweetsToDelete += $tweet
}
}
# Si hay tweets que eliminar, solicitar confirmación al usuario antes de proceder
# If there are tweets to delete, prompt the user to confirm before proceeding
$confirm = Read-Host "Delete tweets (total:$($tweetsToDelete.Count))? (Y/N)" -ErrorAction SilentlyContinue
if ($confirm -imatch "^Y(es)?$") {
foreach ($tweet in $tweetsToDelete) {
$tweetId = $tweet.tweet.id
# PEGAR DEBAJO DE ESTA LINEA (VER PASO 4) / PASTE BELOW THIS LINE (SEE STEP 4)
# CAMBIA EL CODIGO SOLO ARRIBA DE ESTA LINEA / ONLY CHANGE CODE ABOVE THIS LINE
}
Write-Host "Tweets deleted successfully"
} else {
Write-Host "No tweets were deleted"
}
if ($tweetsToDelete.Count -eq 0) {
Write-Host "No tweets found prior to $dateString"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment