Skip to content

Instantly share code, notes, and snippets.

@visualglitch91
Created August 12, 2020 21:57
Show Gist options
  • Save visualglitch91/85f76e6e63f764b878a4eb060b7212b0 to your computer and use it in GitHub Desktop.
Save visualglitch91/85f76e6e63f764b878a4eb060b7212b0 to your computer and use it in GitHub Desktop.
Delete all tweets
(async () => {
const twitterClientToken =
"AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
function getCookie(cname) {
const name = cname + "=";
const decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function api(method, path, options) {
const data = new URLSearchParams(options).toString();
const url =
`https://api.twitter.com/1.1/${path}.json` +
(method === "GET" ? `?${data}` : "");
return fetch(url, {
headers: {
accept: "*/*",
"accept-language": "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7",
authorization: `Bearer ${twitterClientToken}`,
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"x-csrf-token": getCookie("ct0"),
"x-twitter-active-user": "yes",
"x-twitter-auth-type": "OAuth2Session",
"x-twitter-client-language": "en",
},
referrer: "https://twitter.com/compose/tweet",
referrerPolicy: "no-referrer-when-downgrade",
body: method !== "GET" ? data : undefined,
method,
mode: "cors",
credentials: "include",
}).then((r) => r.json());
}
const settings = await api("GET", "account/settings");
async function next() {
console.log("Looking for more tweets...");
const tweets = await api("GET", "statuses/user_timeline", {
screen_name: settings.screen_name,
include_rts: true,
exclude_replies: false,
count: 200,
});
if (tweets.length) {
console.log(`${tweets.length} tweets found!`);
for (let tweet of tweets) {
await api("POST", `statuses/destroy/${tweet.id_str}`);
console.log(`Deleted tweet ${tweet.id_str}`);
}
return next();
}
}
await next();
console.log("No tweets found, we're done!");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment