$url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array( 'Authorization: ' . $key, ), ); // Iniciar cURL $ch = curl_init(); curl_setopt_array($ch, $options); $resposta = curl_exec($ch); // Verificar se houve erros na execução do cURL if (curl_errno($ch)) { echo 'Erro cURL: ' . curl_error($ch); } else { // Decodificar a resposta JSON $resp = json_decode($resposta, true); // Verificar se houve erros na decodificação JSON if (json_last_error() !== JSON_ERROR_NONE) { $erroJson = json_last_error_msg(); echo ""; } else { $imagem = getBanner($resp); } } // Fechar a sessão cURL curl_close($ch); // Funções utilizadas // function getBanner($data) { $imagem_aleatoria = random_int(0, 15); $urlImagem = $data['photos'][$imagem_aleatoria]['src']['original']; if (!$urlImagem) { echo ""; $urlImagem = "img/imageNotFound.jpg"; } return $urlImagem; } function montarUrl($endPoint, $type) { $endPoint .= $type; $params = array( 'query' => 'call center', 'orientation' => 'landscape', 'size' => 'small', ); $url = $endPoint . '?' . http_build_query($params); return $url; } ?>