Twitter API V2 403:禁止使用 tweepy

Twitter API V2 403: Forbidden using tweepy

即使我的帐户处于活动状态,我也无法使用我的 Twitter 开发者帐户进行身份验证

import tweepy
consumer_key= 'XX1'
consumer_secret= 'XX2'
access_token= 'XX3'
access_token_secret= 'XX4'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
api.update_status("Hello Tweepy")

我遇到错误:

Forbidden: 403 Forbidden

453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve

开发者门户上没有从 Essential 到 Elevated 的选项。有什么建议吗?

仪表板中有选项。您必须提交访问申请。

参考图片:

我发现 Essential access 只能使用 Twitter API v2

代码应该是

import tweepy
consumer_key= 'x'
consumer_secret= 'xx'
access_token= 'xxx'
access_token_secret= 'xxxx'

client = tweepy.Client(consumer_key= consumer_key,consumer_secret= consumer_secret,access_token= access_token,access_token_secret= access_token_secret)
query = 'news'
tweets = client.search_recent_tweets(query=query, max_results=10)
for tweet in tweets.data:
    print(tweet.text)

感谢https://twittercommunity.com/t/403-forbidden-using-tweepy/162435/2

除非您的应用有以下特定要求,否则无需“提升”您的访问权限:

“基本”(您默认拥有的)访问权限具有以下权限:

在 OP 所指的情况下,他正在尝试发送推文,因此使用 Tweepy + Twitter API v2 的代码将如下所示:

import tweepy
client = tweepy.Client(consumer_key="",
                    consumer_secret="",
                    access_token="",
                    access_token_secret="")
# Replace the text with whatever you want to Tweet about
response = client.create_tweet(text='hello world')

请记住,您的 access_token + access_token_secret 必须生成具有读写权限才能发送推文(否则您将收到前面代码的 403 错误):

有关如何操作的更多详细信息,请参阅 https://twittercommunity.com/t/how-do-i-change-my-app-from-read-only-to-read-write/163624/4

我的问题是我在将应用程序设置为 read/write 模式之前创建了令牌。令牌使用之前的设置,因此在更改为 read/write 模式后需要重新创建令牌。

从这里开始:https://twittercommunity.com/t/forbidden-to-use-retweet-v2/159706