【问题标题】:Twitter API V2 403: Forbidden using tweepyTwitter API V2 403:禁止使用 tweepy
【发布时间】:2021-12-31 01:21:05
【问题描述】:

即使我的帐户处于活动状态,我也无法使用我的 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 的选项。有什么建议吗?

【问题讨论】:

    标签: python twitter tweepy twitterapi-python


    【解决方案1】:

    我发现 Essential 访问只能使用 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

    【讨论】:

      【解决方案2】:

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

      参考图片:

      【讨论】:

      【解决方案3】:

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

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

      在 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 了解更多详情。

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-04-05
          • 2021-12-31
          • 2022-11-10
          • 2022-12-10
          • 2018-11-24
          • 1970-01-01
          • 1970-01-01
          • 2022-11-03
          相关资源
          最近更新 更多