hi, i found this code online:
https://api.twitch.tv/kraken/oauth2/authorize?
response_type = code & client_id = [client_id] & redirect_uri = [redirect_uri] & scope = user_read + user_subscriptions & state = [state]
and I was wondering how to transform it to the new api and how to brass it you are going to make it work. I am a beginner so I kindly ask you if I could have clear answers.
Thanks in advance.
Dist
July 29, 2021, 10:29am
2
Authentication | Twitch Developers is the documentation for authentication. It has step by step instructions based on what type of token/flow you need.
in this script what do I need to change to make it work for subscribers only?
> <?php
>
> $client_id = '';
>
> $client_secret = '';
>
> $redirect_uri = '';
>
> $broadcaster_id = '';
>
> if (isset($_GET['code']) && $_GET['code']) {
>
> $token_url = "https://id.twitch.tv/oauth2/token";
>
> $data = array(
>
> 'client_id' => $client_id,
>
> 'client_secret' => $client_secret,
>
> 'grant_type' => 'authorization_code',
>
> 'redirect_uri' => $redirect_uri,
>
> 'code' => $_GET['code']
>
> );
>
> $curl = curl_init($token_url);
>
> curl_setopt($curl, CURLOPT_POST, true);
>
> curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
>
> curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
>
> curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
>
> $result = curl_exec($curl);
>
> $i = curl_getinfo($curl);
>
> curl_close($curl);
>
> if ($i['http_code'] == 200) {
>
> $result = json_decode($result, true);
>
> $curl = curl_init('https://api.twitch.tv/helix/subscriptions?broadcaster_id=' . $broadcaster_id . '&user_id' . $user_id);
>
> curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
>
> curl_setopt($curl, CURLOPT_HTTPHEADER, array(
>
> 'Client-ID: ' . $client_id,
>
> 'Authorization: Bearer ' . $broadcasters_token
>
> ));
>
> curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
>
> $subdata = curl_exec($curl);
>
> $i = curl_getinfo($curl);
>
> curl_close($curl);
>
> if ($i['http_code'] == 200) {
>
> $user = json_decode($user);
>
> echo '<p>Thanks ' . $user->data[0]->display_name . ' <3</p>';
>
> } else {
>
> echo '<p>An error occured, please <a href="/index.php">click here and try again</a></p>';
>
> }
>
> } else {
>
> echo '<p>An error occured, please <a href="/index.php">click here and try again</a></p>';
>
> }
>
> } else {
>
> $auth_url = 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=code';
>
> $auth_url .= '&client_id=' . $client_id;
>
> $auth_url .= '&redirect_uri=' . $redirect_uri;
>
> $auth_url .= '&scope=user_read';
>
> $auth_url .= '&force_verify=true';
>
> echo '<a href="' . $auth_url . '">Please Click this Link to Authenticate with Twitch</a>';
>
> }
system
Closed
August 28, 2021, 1:09pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.