Stream always offline (stream web status)

Alright, I’ve actually tested and whatnot. Here’s what’s wrong:

  • You still have duplicate entries in curl_setopt_array, namely CURLOPT_HTTPHEADER.
  • CURLOPT_URL adds $streamName, an undefined variable, to the $url which already has the channel name from its initialization.

Here’s the script I was working with that actually works:

<?php
	$streamChannel = "kamiiq";
	$url = "https://api.twitch.tv/kraken/streams?channel=" . $streamChannel;
	$clientID = "6x31cwwskz31pmkfibymz8un59icd2";
	function file_get_contents_curl($url, $headers) {
		$ch = curl_init();
		curl_setopt_array($ch, [
				CURLOPT_HTTPHEADER => $headers,
				CURLOPT_RETURNTRANSFER => true,
				CURLOPT_URL => $url,
				CURLOPT_AUTOREFERER => TRUE,
				CURLOPT_HEADER => FALSE,
				CURLOPT_RETURNTRANSFER => TRUE,
				CURLOPT_FOLLOWLOCATION => TRUE
			]);
		$data = curl_exec($ch);
		curl_close($ch);

		return $data;
	}
	$headers = [
			"Client-ID: " . $clientID
		];
	$data = file_get_contents_curl($url);
	$json_array = json_decode($data, true);
	if(isset($json_array["streams"][0]["channel"])) {
		echo "( ͡° ͜ʖ ͡°)";
	} else {
		echo "nope";
	}
?>
1 Like