0

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);

Echoed out the payload but no results being printed Echoed out the payload

  • add in https://www.php.net/manual/en/function.curl-error.php – Lawrence Cherone May 10 '22 at 10:58
  • @LawrenceCherone it showed me a Curl error: SSL certificate problem: unable to get local issuer certificate, is it because I'm using it on localhost and not on a website? – AWorkingGuy May 10 '22 at 11:33
  • https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate – CBroe May 10 '22 at 11:34
  • @CBroe thanks for helping me with the problem, the guide showed me how to fix it, and it is now running properly! – AWorkingGuy May 10 '22 at 11:41

0 Answers0