Hey guys,
I dont play often with APIs but a while ago I wrote a bit code too see if one of my friends is live and I used php and Curl to achieve this.
I used:
$link = https://api.twitch.tv/helix/streams?user_login=XXX&user_login=YYY;
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/vnd.twitchtv.v5+json',
'Client-ID: *My-Client-ID*',
));
$l1 = curl_exec($ch);
curl_close($ch);
$twitch_array = json_decode($l1, true);
echo "Twitch Array 1: <br>";
print_r($twitch_array);
All worked fine for me but now i get the error:
Array ( [error] => Unauthorized [status] => 401 [message] => OAuth token is missing )
I searched for this error and after a while I found out that Twitch changed there API so that every request needs an Oauth Token but I am not able to generate one of these for me.
I have a Client- and a Secret Id and this Link:
https://id.twitch.tv/oauth2/token
--data-urlencode
?grant_type=refresh_token
&refresh_token=REMOVED
&client_id=fooid
&client_secret=barbazsecret
Can someone explain me how I get the nessesary Oauth token with these 3 things using Curl?
I have this Code now:
$url = 'https://id.twitch.tv/oauth2/token--data-urlencode?grant_type=refresh_token&refresh_token=REMMOVED&client_id=dM<-Client-ID&client_secret=My-Secret-ID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
I deleted the scope part because I think its not needed for “…/streams/…” and I dont know what I should use for the refresh token.
The error is:
{"status":400,"message":"invalid URL escape \"%6V\""}