【问题标题】:Why can't I delete multiple tweets with this code? Python tweepy为什么我不能使用此代码删除多条推文? Python tweepy
【发布时间】:2020-12-26 09:42:52
【问题描述】:

我正在尝试使用此代码从我的帐户中删除 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 正常发推文,为什么这不起作用?我做错了什么?

【问题讨论】:

  • 您的具体案例看起来像是权限问题。但是,即使您拥有适当的权限,代码仍然会失败。 tweet_id 是一个字典,其中一个键包含 id,所以正确的代码是 tweetid['id']

标签: python api twitter tweepy twitterapi-python


【解决方案1】:

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

Why is the twitter API throwing this error?

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

【讨论】:

  • 那我怎么还能update_status 和其他东西呢?它似乎只是在删除不起作用的推文
【解决方案2】:

听起来您的 API 密钥已受到限制(如果您尝试执行太多自动化操作,可能会发生这种情况,请参阅自动化规则 https://help.twitter.com/en/rules-and-policies/twitter-automation)。您需要通过https://help.twitter.com/forms/automation恢复应用程序

【讨论】:

  • 但是当我尝试提交票证(在相关帐户中)时,它显示“您的帐户既没有暂停也没有锁定”我是否要在错误的区域提交票证?
  • 哦,help.twitter.com/forms/automation 似乎只是重定向回 /forms
  • 好的。那时我可能犯了一个错误。为了让 Stack 成为主题,您可能想访问 Twitter 特定的开发者论坛。如果您可以分享您的应用 ID(而不是使用者密钥等),我们或许可以对其进行调查。我仍然相当确信这是一个应用过度使用问题。
  • 好的,我今天某个时候会在那个论坛上开一个新话题。
猜你喜欢
  • 2021-12-27
  • 1970-01-01
  • 2020-09-24
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 2016-03-25
  • 2020-12-11
  • 1970-01-01
相关资源
最近更新 更多