Twitter API V2 403:使用tweepy被禁止访问

3

尽管我的账户处于活跃状态,但我无法使用我的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 的选项。有什么建议吗?
4个回答

6
除非您的应用程序具有以下特定要求,否则无需“提升”您的访问权限: enter image description here “基本”(默认情况下拥有的)访问权限包括以下内容: enter image description here 在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获取更多关于如何做到这一点的细节。

1
这个在2023年2月对我起作用了,遇到和 OP 相同的错误。 - mdkb

5
我发现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,让编程变得更加容易。


但是这里说 tweepy 没有名为 Client 的属性。 - itti_da
6
我遇到了 tweepy.errors.Unauthorized: 401 Unauthorized 错误。Unauthorized 表示未经授权。 - CountDOOKU
请问,免费的开发者账户是否可以使用“搜索”推文的API? - undefined

3

仪表板中有选项。您需要提交访问申请。

参考图像:

仪表板


1
点击“申请提升权限”会将我重定向到https://developer.twitter.com/en/portal/petition/academic/is-it-right-for-you。 - Bani
这些选项卡似乎已被删除。我只看到“免费”和“基本”选项卡,然后是申请企业访问权限的链接。 - Scott

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接