<?php
// Set the client ID for your app here
$clientID = array(
‘Client-ID: 0000000000000000000000000000000’
);
//Create a function called “file_get_contents_curl” - This will work/replace any usage of the normal “file_get_contents” and will include the required header with ClientID field.
function file_get_contents_curl($url) {
$ch = curl_init();// this area is the curl options being set, to include the URL to be called and the ClientID to be added to the header
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;}
// AT THIS POINT, THE FUNCTION IS CREATED
// Let’s do a sample call, I want to see who my last follower is so I’ll call https://api.twitch.tv/kraken/channels/matt_thomas/follows?limit=1
// Storing the data as apiCALL
$apiCALL = json_decode(@file_get_contents_curl(‘https://api.twitch.tv/kraken/channels/matt_thomas/follows?limit=1’), true);
// Grabbing the field I want, and storing it’s value as ‘$follower’
$follower = $apiCALL[‘follows’][‘0’][‘user’][‘name’];
//echo the value for ‘$follower’
echo $follower;
?>