1

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. [registration_url] => https://developer.twitter.com/en/docs/projects/overview [title] => Client Forbidden [required_enrollment] => Appropriate Level of API Access [reason] => client-not-enrolled [type] => https://api.twitter.com/2/problems/client-forbidden

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.twitter.com/2/users/by/username/'.$user_name,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer *****************',
    'Cookie: guest_id=v1%3A165890613185132504; guest_id_ads=v1%3A165890613185132504; guest_id_marketing=v1%3A165890613185132504; personalization_id="v1_HFyLDpcRdDltg0YkoBj9Ow=="'
  ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;

Twitter api v2 show authentication error. bearer token is regenerated multiple time and it is already attached to project.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Rahul Garg
  • 21
  • 3
  • 1
    Please contact customer service for questions regarding accessing the API with your account. See as well [Why can't I ask customer service-related questions?](https://meta.stackoverflow.com/questions/255745/why-cant-i-ask-customer-service-related-questions-on-stack-overflow/255746#255746) – hakre Jul 18 '23 at 19:35
  • Somewhere, in your Twitter account, you haven't set up your API project properly. That has nothing to do with the code you've shown us. – ADyson Jul 19 '23 at 08:13

0 Answers0