I face some problems when scraping some tweets using Python with module requests using Twitter API. My API is already tagged with V2 ACCESS and my bearer token is from an app under a project which is under development environment. Maybe my screenshots would tell more about my case. I still face errors like this:
{
"title": "Unsupported Authentication",
"detail": "Authenticating with Unknown is forbidden for this endpoint. Supported authentication types are [OAuth 2.0 Application-Only].",
"type": "https://api.twitter.com/2/problems/unsupported-authentication",
"status": 403
}
Anyway, this is my python code:
import requests
import twarc.expansions as expansions
import pandas as pd
search_url = "https://api.twitter.com/2/tweets/search/all"
bearer_token = "XXXX"
def create_headers(bearer_token):
headers = {"Authorization": "Bearer {}".format(bearer_token), "User-Agent": "v2UserTweetsPython"}
return headers
query_params = {'query': 'banjir lang:id has:geo place_country:ID -is:retweet -is:reply -has:mentions -has:links',
'tweet.fields':'created_at,lang,text,geo,author_id,id,public_metrics,referenced_tweets',
'expansions':'geo.place_id,author_id',
'place.fields':'contained_within,country,country_code,full_name,geo,id,name,place_type',
'user.fields':'description,username,id',
'start_time':'2023-05-01T00:01:01.000Z',
'end_time':'2023-05-31T23:59:00.000Z',
'max_results':'10'}
headers = create_headers(bearer_token)
response = requests.get(search_url, params=query_params, headers=headers) # error here
Can you all help me, please? I can’t find any links refer to official twitter support tickets, forms, or something else. Thank you so much~
I need to fix this problem due to my final thesis deadline as soon as possible :"

