Hello! there is a code that should receive information from the twitch channel

<?$channelName = htmlspecialchars($_GET['channel'], ENT_QUOTES); //Получаем ID здесь http://www.twitch.tv/settings?section=applications $clientId = 'dreamhackcs'; //подставляем значение в переменную online $online = 'Online'; //подставляем значение в переменную offline $offline = 'Offline'; $json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true); if ($json_array['stream'] != NULL) { $channelTitle = $json_array['stream']['channel']['display_name']; $streamTitle = $json_array['stream']['channel']['status']; $currentGame = $json_array['stream']['channel']['game']; $delay = $json_array['stream']['channel']['delay']; $logo = $json_array['stream']['channel']['logo']; echo "Пользователь: $channelTitle <br> Статус: $online <br> Сейчас в игре: $currentGame <br> Задержка: $delay <br> Логотип: $logo"; } else { echo "$channelName в данный момент $offline />"; }?> 

But here it gives an error:

Warning: file_get_contents ( https://api.twitch.tv/kraken/streams/?client_id=dreamhackcs ) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP / 1.1 400 Bad Request in V: \ home \ reg.su \ www \ index.php on line 10 РІ РґР ° РЅРЅС ‹Р№ РјРѕРјРµРС‚ Offline />

2 answers 2

  1. Go https://www.twitch.tv/settings/connections
  2. Create an application.
  3. We configure, specifies where requests will go from, and we receive Client-ID

    $ channelsApi = ' https://api.twitch.tv/kraken/channels/ ';

    $ channelName = 'twitch';

    $ clientId = 'axjhfp777tflhy0yjb5sftsil';

    $ ch = curl_init ();

    curl_setopt_array ($ ch, array (

     CURLOPT_HTTPHEADER => array( 'Client-ID: ' . $clientId ), CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $channelsApi . $channelName 

    ))

    $ response = curl_exec ($ ch);

    curl_close ($ ch);

    Peep! and no problem

     <?$channelName = silvername; //Получаем ID здесь http://www.twitch.tv/settings?section=applications $clientId = 'dzayarr9nbqawy297yopktokswn75a'; //подставляем значение в переменную online $online = 'Online'; //подставляем значение в переменную offline $offline = 'Offline'; $json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true); if ($json_array['stream'] != NULL) { $channelTitle = $json_array['stream']['channel']['display_name']; $streamTitle = $json_array['stream']['channel']['status']; $currentGame = $json_array['stream']['channel']['game']; $delay = $json_array['stream']['channel']['delay']; $logo = $json_array['stream']['channel']['logo']; echo "Пользователь: $channelTitle <br> Статус: $online <br> Сейчас в игре: $currentGame <br> Задержка: $delay <br> Логотип: $logo"; } else { echo "$channelName в данный момент $offline />"; }?>