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.