Hello Guys,
I am trying to see if stream of particular user is online or offiline in my PHP and here is my try so far.
<?php
// Get Live Streams
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: **********************',
'Authorization: Bearer **************',
'Accept: application/vnd.twitchtv.v5+json'
));
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = "https://api.twitch.tv/helix/streams";
$json_array = json_decode(file_get_contents_curl($url), true);
echo '<pre>';
print_r($json_array);
exit;
// 71588578
?>
Here I am using helix as my channel and I am getting response having id,game_id etc in response … but when I am trying to get other channel’s streams for example this url https://api.twitch.tv/emadgg/streams with my this api url $url = “https://api.twitch.tv/emadgg/streams”; , I am not getting any response … its blank in return.
I have also tried with some other channels $url = “https://api.twitch.tv/swagg/streams”; but none of them working for me except for helix channel. Not sure why …
Basically here I want to know if stream is live or not. But its not working. can someon guide me what I am doing wrong here ?
I am following this thread https://dev.twitch.tv/docs/api/reference/#get-streams.
Additionally, I am using Twitch IRC to get live chat results like this Chat bot in php CLI