Implement OAuth on twitch team website

I’m not sure you mean oauth, but rather just lack a clientID on your API query.

You can add the clientID in the URL

$dataArray = json_decode(@file_get_contents(‘https://api.twitch.tv/kraken/streams?client_id=xxxxxxxxxxxxxxxxxxxxxxxxx&channel=’ . $callAPI), true);

But it is preferred to make the request via headers which can be accomplished via cURL

/* file_get_contents replaced with curl function */
function file_get_contents_curl($url) {
$clientID = array(
“Client-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
);

$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, $clientID);
$data = curl_exec($ch);
curl_close($ch);
return $data;

}

Using this you could put in your clientID once and call file_get_contents_curl to replace any instance of file_get_contents

2 Likes