Skip to content

Instantly share code, notes, and snippets.

@rigwild
Created April 24, 2021 16:57
Show Gist options
  • Save rigwild/3c95b86800344502ae535a0c4a2c6a6c to your computer and use it in GitHub Desktop.
Save rigwild/3c95b86800344502ae535a0c4a2c6a6c to your computer and use it in GitHub Desktop.
Clear all your Twitter account tweets and likes
import { TwitterClient } from 'twitter-api-client' // yarn add twitter-api-client
// You can use this project to get your user token:
// To see your token, add `console.log(tokens)` in `OAuth Step 3` in `express/src/index.js`
// https://github.com/QuodAI/tutorial-react-twitter-api-login
const twitterClient = new TwitterClient({
apiKey: '', // app client id
apiSecret: '', // app client secret
accessToken: '', // user access token
accessTokenSecret: '' // user access token secret
})
const user_id = 'rigwild_'
const delay = (ms: number) => new Promise(res => setTimeout(res, ms))
const deleteTweets = async (max_id?: string) => {
const tweets = await twitterClient.tweets.statusesUserTimeline({ user_id, count: 50, ...(max_id ? { max_id } : {}) })
if (tweets.length === 0) return
for (const tweet of tweets) {
console.log(`Deleting tweet ${tweet.id_str} - ${tweet.text.slice(0, 160).replace(/\n/g, ' ').trim()}`)
await twitterClient.tweets.statusesDestroyById({ id: tweet.id_str }).catch(console.error)
}
console.log('Waiting 10s')
await delay(10000)
await deleteTweets(tweets[tweets.length - 1].id_str)
}
const deleteLikes = async (max_id?: string) => {
const likes = await twitterClient.tweets.favoritesList({ count: 50, user_id, ...(max_id ? { max_id } : {}) })
if (likes.length === 0) return
for (const like of likes) {
console.log(`Deleting like from ${like.id_str} - ${like.text.slice(0, 160).replace(/\n/g, ' ').trim()}`)
await twitterClient.tweets.favoritesDestroy({ id: like.id_str }).catch(console.error)
}
console.log('Waiting 10s')
await delay(10000)
await deleteLikes(likes[likes.length - 1].id_str)
}
;(async () => {
await deleteTweets()
await deleteLikes()
})().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment