Bearer token is not working in tweepy v2 (4.14.0) StreamingClient

208 Views Asked by At

I am trying to make a twitter streamer but it is showing an error.

import tweepy

class streaming_client(tweepy.StreamingClient):
    
    def on_tweet(self, tweet):
        #print(f"{tweet.text}")
        print(tweet.data)
        print("-"*30)

bearer_token = "XXXXXXXXX"
printer = streaming_client(bearer_token=bearer_token)

rule = tweepy.StreamRule(value="Python")
printer.add_rules(rule)
 
printer.filter()

It is showing this error:

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.

I am quite confused as the documentation says to use the bearer token. My bearer token is from an app that is under a project. Does anyone know if there is something wrong with my code? Thanks.

0

There are 0 best solutions below