PHP check to see if stream is live not working

Can anyone point me in the right direction? I know I’m close but this code isn’t working yet.

EDIT: I figured out what’s wrong (I think), but need helping implementing it. Oauth is missing, I have no idea on how to include this here though or how to generate the Oauth code.

<?php
// Options

$clientID = 'MY_SECRET_CLIENT_ID';
$channelName = 'mavemixes';

$baseURL = 'https://api.twitch.tv/helix/';
$url = $baseURL . 'streams?user_login=' . $channelName;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Client-ID: ' . $clientID ]);
$json = curl_exec($ch);
curl_close($ch);

$data = json_decode($json);
if(count($data->data)) {
	echo '<h1>We're live!</h1>';
	echo '<div id="twitch-embed"></div>';
}else{
	echo '<h3>Currently not streaming. <br>Follow MaveMixes on Twitch and get instantly notified when we are live.</h3>';
	
}
?>
<script>
  new Twitch.Embed("twitch-embed", {
    width: 1000,
    height: 600,
    channel: "mavemixes",
    layout: "video",
  });
</script>

Thanks in advance!

Documentation is here

You probably want to be generating storing and using until expires an app access token

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.