问题描述
我正试图使用此代码从我的帐户中删除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
时,它成功捕获了我的所有推文。我也可以使用api.update_status
正常鸣叫,为什么这不起作用?我在做什么错了?
解决方法
好像您已经对twitter api发出了许多请求-从我的小小的研究中,错误代码261表示该令牌已被暂停。检查此链接:
Why is the twitter API throwing this error?
https://blog.cotten.io/common-twitter-error-codes-6b324396042e
,听起来您的API密钥已受到限制(如果您尝试执行太多的自动化操作,请参阅自动化规则https://help.twitter.com/en/rules-and-policies/twitter-automation,这可能会发生)。您需要通过https://help.twitter.com/forms/automation
恢复该应用