I have produced some code that requests a bearer token from an endpoint and adds a new key with a datetime value with seconds that get added to it. This code also produces a fatal error as in the title of this question on line 66:
function requestBearerToken()
{
global $username, $password;
$base_url = 'https://example-url.com/endpoint';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ($base_url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array(
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode("$username:$password"),
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//$data = curl_exec($ch);
curl_close($ch);
$data['expires_on'][0] = date("d-m-Y H:i:s", (time() + 580));
file_put_contents("bearer.json", $data);
$pre_result = json_decode($data, true);
$token = $pre_result;
print_r($token);
}
The reponse body, $data, is as follow:
{
"access_token": "<access_token>",
"token_type": "Bearer",
"expires_in": 299,
"scope": "<scopes>"
}