I tried following the replied guide on this post here How to shorten URL using PHP Bitly v4? but it doesn't really work.
this is my code so far with added variables to match what's on the bitly API documentaiton
$long_url = 'https://stackoverflow.com/questions/60732875/how-to-get-bitly-clicks-using-api-v4-with-php';
$group_guid = 'mygroupid';
$domain = 'bit.ly';
$apiv4 = 'https://api-ssl.bitly.com/v4/shorten';
$genericAccessToken = 'myaccesstoken';
$data = array(
'long_url' => $long_url,
'domain' => $domain,
'group_guid' => $group_guid
);
$payload = json_encode($data);
echo $payload;
$header = array(
"Authorization: Bearer ".$genericAccessToken,
"Content-Type: application/json"
);
$ch = curl_init($apiv4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
print_r($result);