New API rules breaking old script, help

Ok. Really, I can’t thank you all enough for your help.

For the benefit of others trying to implement this update on an old-fangled system, I’ll include my solution below. Note that I consider this incomplete, as I haven’t yet added a fallback in the event of token authentication failure. I’ll leave my comments in place.

I also noticed that it doesn’t appear to update as quickly as before, there is some delay between the time a stream begins, and the time this function returns as true. Any thoughts on why that might be, or something I can do to improve the situation?

function twitch_stream_live() {

	//get an OAuth token from Twitch

	$ch = curl_init("https://id.twitch.tv/oauth2/token");
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	$fields = array(
	    'client_id' => '[client id here',
	    'client_secret' => '[app secret here]',
	    'grant_type' => 'client_credentials',
	    'token_type' => 'bearer',
	    // 'redirect_uri' => 'http://localhost/php/twitch.php',
	    'state' => $_GET['state']
	);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
	$data = curl_exec($ch);

	$info = curl_getinfo($ch); 

	$obj = json_decode($data, true); 
	$token = $obj['access_token'];

	if($token){

		// pass the token to ask the Helix API if we are live

		$tw = curl_init('https://api.twitch.tv/helix/streams?user_login=[user login here]');
		curl_setopt($tw, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($tw, CURLOPT_HTTPHEADER, array(
		    'Client-ID: [client id here again]',
		    'Authorization: Bearer '.$token
		));
		$r = curl_exec($tw);
		curl_close($tw);

		$obj = json_decode($r, true); 

		$data = $obj['data'][0];

		if ($obj['data'][0] ){
			return true;
		}else{
			return false;
		}

	} //end if token
	// need to add a fallback for token failure here

}//end function