- I tried to get the OAuth authorization code using this following GET request :
https://id.twitch.tv/oauth2/authorize?response_type=code&client_id=xxx&redirect_uri=xxx&scope=user:read:email
-
Then I can able to get the code, after that I send this POST request :
$endpoint = "https://id.twitch.tv/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=authorization_code&redirect_uri=xxx&code=xxx"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_POST, true); $contents = curl_exec($ch); curl_close($ch);
-
I received this response :
{"access_token":"xxx","expires_in":15047,"refresh_token":"xxx","scope":["user:read:email"],"token_type":"bearer"}
-
Once I get the access token then I trying to make a request to get this video info (Twitch) :
$endpoint = 'https://api.twitch.tv/helix/videos?id=' . $videoId; $header = array(); $header[] = 'Client-ID: clientId'; $header[] = 'Authorization: Bearer accesstoken'; curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $result = curl_exec($ch); curl_close($ch);
Then it return me “Invalid OAuth token” response, hope someone can guide me regarding this
Client error:
GET https://api.twitch.tv/helix/videos?id=642942113resulted in a
401 Unauthorized response: {"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}