Is giving me head-ache if anyone could help me figure it out - I would be deeply thankful!
I’m calling everything from my backend - so I figured I need
OAuth Client Credentials Flow which is app access token for server-to-server API requests (am I right here? If not - which else should I choose?)
First I created an application - got Client ID and Client Secret from it.
Then I created the following function
function getOAuthID(){
$url = 'https://id.twitch.tv/oauth2/token?client_id=xxxx&client_secret=xxxx&grant_type=client_credentials&scope=user_read';
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$resultArray = explode('"', $result);
return $resultArray[3];
}
As I’ve read I need the scope: user_read - which I put in params.
Then I proceeded to create a php curl request as instructed for Get Followed Streams guide -
$url = 'https://api.twitch.tv/kraken/streams/followed';
$clientID = 'xxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/vnd.twitchtv.v5+json',
'Client-ID: '.$clientID,
'Authorization: OAuth '.getOAuthID()
));
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
Where I get following response…
{"error":"Unauthorized","status":401,"message":"invalid oauth token"}
But I checked the status of my OAuth on https://api.twitch.tv/kraken/
and got back feedback:
{"token":{"valid":true,"authorization":{"scopes":["user_read"],"created_at":"2019-11-21T17:03:03Z","updated_at":"2019-11-21T17:03:03Z"},"client_id":"xxx","expires_in":5379463}}
I’m lost here… Anyone has any idea that could help me out - even some suggestions what to try?
Could it have anything to do with my access token being
token_type":“bearer”