<?php $clientID = 'clientid'; $sclientID = 'clientsecret'; if(!empty($_GET["code"])) { $token = $_GET["code"]; $tokenid= $_GET["id_token"]; echo $tokenid; // PRMEIERE REQUETE $ch = curl_init(); $url = 'https://id.twitch.tv/oauth2/token'; $opts = [ CURLOPT_URL => $url, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => false ]; $post = [ 'client_id' => $clientID, 'client_secret' => $sclientID, 'code' => $token, 'grant_type' => 'authorization_code', 'redirect_uri' => 'http://tworld.lescigales.org/api.php' ]; curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt_array($ch, $opts); $response = curl_exec($ch); $json_array = json_decode($response, true); curl_close($ch); $validate_token = $json_array['access_token']; //$userinfo = $json_array['userinfo']; //echo $userinfo; echo '<br><br><br>'; // SECONDE REQUETE $ch = curl_init(); $url = 'https://api.twitch.tv/helix/users'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt ($ch, CURLOPT_HTTPHEADER, array ( 'Authorization: Bearer '. $validate_token, 'Client-ID: '. $clientID )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); $response = curl_exec($ch); echo $response; curl_close($ch); $json_array = json_decode($response, true); echo $json_array; } else{ echo '<a href="https://id.twitch.tv/oauth2/authorize?client_id=' . $clientID . '&redirect_uri=http://tworld.lescigales.org/api.php&response_type=code&scope=user_read">Connexion</a>'; } ?>