Search code examples
pythontwittertweepy

Can't query Twitter API v2 with elevated acces project/app


I'm trting to query Twitter API v2 with elevated research access via tweepy, but it still gives me a 403 Forbidden. evelevated acces proof of my app

client = tweepy.Client(
    bearer_token=BEARER_TOKEN,
#    consumer_key=CONSUMER_KEY,
#    consumer_secret=CONSUMER_SECRET,
#    access_token=OAUTH_ACCESS_TOKEN,
#    access_token_secret=OAUTH_ACCESS_TOKEN_SECRET,
    
)

test = client.search_all_tweets(query="#something",
                                start_time = "2023-01-01")
print(test)

Response:

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've tried all the combinations of the commented lines when created the client, nothing works.

What am I doing wrong?

No problem with normal access endpoints and bearer_token param. However, can't nothing when using consumer_key/secret and acces_token(_secret) instead. Maybe this is the real issue?

Thank you in advance.


Solution

  • This table shows which account access or not

    If you has free account (Essential or Elevated), you can't use search_all_tweets method. It is equivalent the GET /2/tweets/search/all API.

    enter image description here

    You can check which account has in your Developer Portal

    https://developer.twitter.com/en/portal/products
    

    In the three tabs (Essential, Elevated, and Academic Research), Checked green item is your account. enter image description here

    But you can use recent 7 days search API by search_recent_tweets() even if free account.

    That is equivalent with GET /2/tweets/search/recent