more simply I just have that subscribers can access non-subscribers are reported to the index with an error message
Pardon? Not sure what you mean here
I mean that, before I wanted each subscription level to have a page, now it is enough that each subscriber can enter the same page regardless of the subscription level, then non-subscribers are reported to the index to receive an error message saying they are not subscribers .
So it’s working then?
no, I was wondering if he could get this thing into my code
you already have all the parts you need you just need to write the if statements and flow to match your needed conditions
what is the scope to check if the user is a subscriber?
as documented in the docs I linked earlier
it’s channel:read:subscriptions
<?php
$client_id = '';
$client_secret = '';
$redirect_uri = '';
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/user');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Client-ID: ' . $client_id,
'Authorization: Bearer ' . $result['access_token']
));
curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
$user = curl_exec($curl);
$i = curl_getinfo($curl);
curl_close($curl);
if ($i['http_code'] == 200) {
$user = json_decode($user);
echo '<p>Thanks ' . $user->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=channel:read:subscriptions';
$auth_url .= '&force_verify=true';
echo '<a href="' . $auth_url . '">Please Click this Link to Authenticate with Twitch</a>';
} elseif{
$auth_url . = false{
header("Location: index.php");
echo = "you are not a subscriber";
}
}
would this last part work?
No, it’s syntax is wrong, you go if, else, else if
and the elseif has no clause
That’s seems to be an oAuth loop to get a token with channel:read:subscriptions
echo = "you are not a subscriber";
suggests you are trying to do a subscriber check here, but this is just a loop to get the authentication/permission from the broadcaster
excuse me, i know i’m stressing you, can you try in no hurry to modify the code and add the new parts to check it? Please!
hi, i’m indebted to a job on this, could someone fix my script with subscriber control? Thanks!!
You’ve been given the relevant information, samples and explanation on how the flow.
We cannot do all your work for you.
Get and store a key from the broadcaster with the channel:read:subscriptions
and refresh said key as needed
Then a regular user will Login to your website
Then use the broadcasters key with the logged in user ID against the broadcaster subscriptions API to check status
It’s not a single script, it’s two web pages/flows and a cronjob to maintain the broadcasters key.
You can even modify the user authentication script I already gave you to get the broadcasters key, you just need to determine where you want to store the broadcasters key for reuse
hello I ask with all my heart, could someone make my request work? i can’t it’s since my last post i try day and night to make it work but i can’t, thanks in advance.
Hey guys so could someone provide me with the missed scripts to complete my project, I know it’s annoying but for a good cause.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.