如何使用Python删除所有旧推文

我不喜欢将太多的“历史性”推文与所有我所推文的愚蠢的事情放在一起的想法。

所以我决定全部删除。

为此,我从Twitter设置中请求在Twitter上保存所有我的推文的存档。

存档可能需要几天的时间才能生成。我的存档可以追溯到2015年,尽管我从2007年开始使用Twitter。也许我已经在2015年删除了过去的推文,但我不记得了。

我得到了存档,下载了,然后解压缩了文件夹,然后运行了

python -m venv .venv
source .venv/bin/activate.fish
python -m pip install delete-tweets

然后,我创建了环境变量来设置运行整个过程所需的Twitter应用程序的键,如上所述。https://github.com/koenrh/delete-tweets

export TWITTER_CONSUMER_KEY="your_consumer_key"
export TWITTER_CONSUMER_SECRET="your_consumer_secret"
export TWITTER_ACCESS_TOKEN="your_access_token"
export TWITTER_ACCESS_TOKEN_SECRET="your_access_token_secret"

I used the consumer and access keys of a Twitter app I already had (Twitter now has a process to create new apps, so you must be reviewed and approved to do the same if you don’t have an app already there).

Tip: when you define environment variables in this way, they are recorded by default in the shell history. To avoid that with the Fish shell, run a new shell with fish --private to start the shell in private mode.

Then I ran:

delete-tweets --until 2021-01-01 tweet.js

to delete all the tweets I tweeted before 2021. It took a little while, but it worked.

It took way more to get the archive from Twitter than to delete the tweets, but in the end I got a clean slate.