There is no API that provides “online” data for a user.
Hi, Barri, I don’t know if you can help me, I’ve been eating my head for two days, how can I save this JSON in a database, thank you.
object(stdClass)#4 (12) {
[“broadcaster_id”]=>
string(9) “507703972”
[“broadcaster_login”]=>
string(12) “ragnarok1978”
[“broadcaster_name”]=>
string(12) “ragnarok1978”
[“gifter_id”]=>
string(0) “”
[“gifter_login”]=>
string(0) “”
[“gifter_name”]=>
string(0) “”
[“is_gift”]=>
bool(false)
[“plan_name”]=>
string(36) “Suscripción de canal (ragnarok1978)”
[“tier”]=>
string(4) “1000”
[“user_id”]=>
string(9) “540802131”
[“user_name”]=>
string(16) “adrifortnite2020”
[“user_login”]=>
string(16) “adrifortnite2020”
}
the JSON is brought from:
file_put_contents(DIR . ‘/auth.json’, $r, JSON_PRETTY_PRINT);
That question is beyond the scope of this forum really.
Thats a lot of “what ifs” which depends on your Langauge, Database engine and other stuff.
So you just need a basic langauge/db primer on the language you are using.
This code is yours from twitch_misc-main-> authentication-> user_access_generator-> php-> index.php.
it works fine but I want to save the values that the JSON shows me in MYSQL on localhost.
If I don’t continue, let’s see if I can find it, it is the way I have seen to update the data of the users if they are subscribers or not.
Yup and that code exists to demonstrate how to generate a token in PHP as simply as possible
As then you can take other knowledge and do what you want with it.
So it doesn’t give an opinion about database or how/where to store tokens or data
Thats on you. It’s outside the scope of “Twitch API”
There is no method to get that information received to a database …?
In PHP sure.
But thats nothing to do with Twitch API.
Heres the PHP manual for MYSQLi PHP: MySQLi - Manual
That code is helping me a lot in the TWITCH API, that’s why I want to continue using and expanding it. Thanks for the help
I do not know what I do badly.
if (json_last_error() == JSON_ERROR_NONE) {
// el token es bueno
// vamos a obtener el usuario para el que es este token
//$ch = curl_init(‘https://api.twitch.tv/helix/subscriptions?broadcaster_id=507703972&user_id=’ . $idtwitch);
$ch = curl_init(‘https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=507703972’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ’ . CLIENT_ID,
'Authorization: Bearer ’ . $_SESSION[‘token’]->access_token
));
error:Helix did not return a single user
Err thats coz you are calling the channel rewards endpoint. That won’t return subscrubers
I do not want subscribers only channel rewards endpoint.
$ch = curl_init(‘https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=507703972’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: ’ . CLIENT_ID,
'Authorization: Bearer ’ . $_SESSION[‘token’]->access_token
));
I don’t know if that’s the case.
If the response is blank, then that suggests there are no custom rewards available to return.
Assuming you didn’t get an error message.
$error = ‘Helix returned not one user’;
If you are using my code example for loading a user from a token
That code does if (count(response -> data) != 1) return an error
So you either got zero rewards or more than one reward returned.
So you are using my code example wrong for this endpoint
If it’s your code, I don’t know what I’m doing wrong, I’ll check it to see what I’m doing wrong
I get this error back in eventsub.
Error get subs 401 {
error: ‘Unauthorized’,
status: 401,
message: ‘Must provide valid app token.’
}
The token requested it I think correctly:
login: ragnarok1978
scopes: Array ( [0] => channel:manage:redemptions [1] => channel:read:redemptions [2] => user:read:email )
user_id: 507703972
expires_in: 14528
EventSub only access “app access tokens” as the error said, this is also known as “Client Credentials”
See: How does Twitch’s new EventSub work? – Barry Carlyon
And: Getting Tokens: OAuth | Twitch Developers
EventSub checks “if the scope is granted” another way by checking if it was granted to the ClientID or not regardless of the token itself, since with EventSub the token won’t represent a user (or have scopes)
I’m going to see, thanks Barri
Hi Barri, I wanted to know something.
I am building a shop for my twitch channel, I don’t use channel points nor do I use channel bit for the shop.
I have read the TOS / Bits rules and they are not violated, my question is:
for having a store that gives you points for the time you watch the twitch channel, including the rules?
I don’t use any eventsub, or anything like that, just the registration with the twitch account.
Thanks
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.