On my Wordpress site I want to check if specific user is live and if it is, get that streamer public info (Steam thumb, title etc) . With this new token requirement I am running into “OAuth token is missing” error.
As I understand, first I need to get the token. Here is how I get token…
$clientId = '123';
$secret = '456';
$user = 'anomaly';
$ch = curl_init();
$url = "https://id.twitch.tv/oauth2/token?client_id=$clientId&client_secret=$secret&grant_type=client_credentials";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$token = curl_exec($ch);
It will return me something like this…
{"access_token":"REMOVED","expires_in":4845352,"token_type":"bearer"}
Next I am going to make request to URL that is supposed to return me the data.
$url = "https://api.twitch.tv/helix/streams?user_login=$user";
$header = [
"Client-ID: $clientId",
"Authorization: Bearer $token->access_token",
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$data = curl_exec($ch);
curl_close($ch);
If I now var_dump
out the $data
I will get…
{"error":"Unauthorized","status":401,"message":"OAuth token is missing"}"