Authentication token

Hello, I need authorization via twitch api.
I am using:
https://api.twitch.tv/kraken/oauth2/authorize ?response_type=token &client_id=[your client ID] &redirect_uri=[your registered redirect URI] &scope=[space separated list of scopes]

This is the code:

$ku_twhitch = curl_init();
$query = “response_type=token&client_id=”.CLIENT_ID."&redirect_uri=".REDIRECT_URI."&scope=".SCOPE;
curl_setopt($ku_twhitch,CURLOPT_URL,URL_TWITCH_AUTCH."?".$query);
curl_setopt($ku_twhitch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ku_twhitch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ku_twhitch,CURLOPT_RETURNTRANSFER,TRUE);
$result = curl_exec($ku_twhitch);
curl_close($ku_twhitch);
print_r($result);
Can’t get the token, after running, I get redirect to REDIRECT_URI and blank page.
Tell me, how I can the token vie curl method?

The implicit grant flow you are using cannot be used with cURL as the authorization hand shake is taking place entirely within your users browser. First you to present the kraken/oauth2/authorize URL to your end user via a link or redirect and so they can choose to allow or deny your app in their browser. If they allow it will then redirect back to your redirect url with the token in the URL hash (which is inaccessible to a PHP script).

If you are going to be using PHP you will want to use the Authorization code flow as described here: https://github.com/justintv/Twitch-API/blob/master/authentication.md#authorization-code-flow which add and additional step which you will use cURL for.

1 Like

Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.