louisa
#1
I am trying to test my academic track access by using the full search.
I saved academic project’s bearer_token and have passed it to request.
However, I get the following error:
403, ‘{“client_id”:“7023832”,“detail”:“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.”,“title”:“Client Forbidden”,“required_enrollment”:“Standard Basic”,“reason”:“client-not-enrolled”}’
How exactly are you making the calls? Do you have a code sample? and are you using the bearer token or giving some code or library consumer keys or an access token? Also is the app for which you’ve generated a bearer token attached to the right Project on https://developer.twitter.com/en/portal/dashboard ?
louisa
#3
Thanks for the quick response.
Here’s my code sample. I am using the bearer token and I only apply for one app in one project. Is there any place I need to specify the project?
search_url = "https://api.twitter.com/2/tweets/search/all"
query_params = {
'start_time': '2021-02-04T00:00:00Z', # YOUR START DATE IN YYYY-MM-DDT00:00:00Z Format
'end_time': '2021-02-10T00:00:00Z', # YOUR START DATE IN YYYY-MM-DDT00:00:00Z Format
'tweet.fields': 'author_id,created_at,in_reply_to_user_id,possibly_sensitive,public_metrics,lang,source',
'max_results': 500, #This is the max results admited by API endpoint
'expansions': 'attachments.media_keys,author_id',
'media.fields': 'duration_ms,media_key,url,type,public_metrics',
'user.fields': 'username',
}
# This is an example of multiple queries in same work.
pharses = [
{"value": "#Buccaneers -is:retweet"}, # This will retreieve all Tweets with this exact hashtag, and will descard retweets.
{"value": "from:Buccaneers"}, # This will retreieve all Tweets From Bucaneers account, including retweets.
]
bearer_token = 'bear token'
def create_headers(bearer_token):
headers = {"Authorization": "Bearer {}".format(bearer_token)}
return headers
def query(headers, params):
response = requests.request("GET", search_url, headers=headers, params=params)
if response.status_code != 200:
raise Exception(response.status_code, response.text)
return response.json()
headers = create_headers(bearer_token)
for pharse in pharses:
pharse = pharse["value"]
query_params["query"] = pharse
json_response = query(headers, query_params)
Also, I don’t know if it is related, it seems that my account is a team account for academic research.
I tried to add more members to the dashboard but always get this error.
That looks correct, and no - you don’t specify the project anywhere in code, it’s just in the dashboard.
I think this might be the problem - I saw in another thread Twitter saying Team accounts are not supported for Academic Access, and you have to fill in some other form for support on that -
louisa
#5
Thanks so much for your help. I think that’s the problem.