i have problem with one task - "your task will be to unhardcode photo getter by applying connection to Example Api. It's a simple JSON API with only one endpoint: http://exampleapi.com/
It is protected by API key. To be authorized you must pass api_key GET parameter to the endpoint. The key that you may use is 45adfxcvpas4aw4asd870cz34876azx6
As a response for request to this API you will get simple JSON object with just one attribute called "url", eg. {"url": "http://randombuilding123.jpg"}.
I write this function but its still sends me to 404 page. What im doing wrong Code :
public function getUrl(): string
{
$url= 'http://exampleapi.com/';
$ch = curl_init($url);
$apikey= '45adfxcvpas4aw4asd870cz34876azx6';
$headers = array(
'Authorization: '.$apikey
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if(!$response){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
curl_close($ch);
return '/images/404.jpg';`