tweepy.errors.Forbidden: 403 Forbidden - Issue with Twitter API authentication using Tweepy
Asked Answered
F

1

5

I'm encountering

tweepy.errors.Forbidden: 403 Forbidden
When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.

while trying to run the following code that fetches a user's post history using the Twitter API and Tweepy:

    client = tweepy.Client(bearer_token=bearer_token)
    tweets = client.search_recent_tweets(query=f'from:{user_handle}')

My app does seem to be connected to a project (see img) I have come across some links that suggest it might be a Twitter issue related to API authentication. However, I would like to confirm if this is indeed the case and if there are any possible solutions or workarounds for this problem.

Links indicating it might be a Twitter issue:

https://github.com/twitterdev/Twitter-API-v2-sample-code/issues/58 https://twittercommunity.com/t/when-authenticating-requests-to-the-twitter-api-v2-endpoints-you-must-use-keys-and-tokens-from-a-twitter-developer-app-that-is-attached-to-a-project-you-can-create-a-project-via-the-developer-portal/189699

I would greatly appreciate any insights, explanations, or potential solutions to resolve this issue.

enter image description here

Fissiparous answered 20/6, 2023 at 22:59 Comment(0)
C
9

Your app has the Free access tier which only allows:

  • Posting tweets with the Twitter API v2
  • Media Upload and Login With Twitter with the Twitter API v1.1

To do anything else, you need at least the Basic access tier, which costs some money.

The access tiers are documented in https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api

And of course you should use a recent version of Tweepy that supports the V2 API.

Cuspidor answered 21/6, 2023 at 6:50 Comment(3)
ok, i understand now why my code is not working, this is extremely SAD for that platform tbh ! Thanks elon.Ablebodied
Hi! I have free access and post a tweet good, and after get the 403 for many hours... Works only 2 or 3 times a day, any sugest?Hellenism
Are you trying to post the same text again and again? There are time based limits on duplicate tweets.Cuspidor

© 2022 - 2025 — McMap. All rights reserved.