首页 > 解决方案 > 为什么我不能使用此代码删除多条推文?Python tweepy

问题描述

我正在尝试使用此代码从我的帐户中删除 550 条推文,因为我想再次将其用作我的个人帐户,而没有来自我的机器人的推文:

import tweepy
import json

auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")

auth.set_access_token("access_token", "access_token_secret")

api = tweepy.API(auth)

screen_name = "YOUR_TWITTER_HANDLE"

timelines = api.user_timeline(screen_name, count = 550, include_rts = False)

for status in timelines:
    tweetid = status._json
    api.destroy_status(tweetid)

但是每次我运行它时,我都会收到这个错误:

tweepy.error.TweepError: [{'message': 'Application cannot perform write actions. Contact Twitter Platform Operations through https://support.twitter.com/forms/platform', 'code': 261}]

当我打印tweetid时,它成功地抓取了我所有的推文。我也可以正常使用 tweet api.update_status,为什么这不起作用?我究竟做错了什么?

标签: pythonapitwittertweepytwitterapi-python

解决方案


似乎您已经对 twitter api 提出了许多请求 - 从我的小研究中,错误代码 261 表示令牌已暂停。检查此链接:

为什么 twitter API 会抛出这个错误?

https://blog.cotten.io/common-twitter-error-codes-6b324396042e


推荐阅读