# Check user if subscribed to my channel

**URL:** <https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187>\
**Category:** API\
**Created:** [June 18, 2021, 1:38pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187 "2021-06-18T13:38:51Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 21, 2021, 3:31pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/41 "2021-06-21T15:31:29Z")

</div>

There is no API that provides “online” data for a user.

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 23, 2021, 5:08pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/42 "2021-06-23T17:08:34Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 23, 2021, 5:10pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/43 "2021-06-23T17:10:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 23, 2021, 5:18pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/44 "2021-06-23T17:18:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 23, 2021, 5:20pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/45 "2021-06-23T17:20:20Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 23, 2021, 5:23pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/46 "2021-06-23T17:23:17Z")

</div>

There is no method to get that information received to a database …?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 23, 2021, 5:24pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/47 "2021-06-23T17:24:15Z")

</div>

In PHP sure.

But thats nothing to do with Twitch API.

Heres the PHP manual for MYSQLi [PHP: MySQLi - Manual](https://www.php.net/manual/en/book.mysqli.php)

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 23, 2021, 5:25pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/48 "2021-06-23T17:25:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 30, 2021, 6:26pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/49 "2021-06-30T18:26:11Z")

</div>

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=](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](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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 30, 2021, 6:27pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/50 "2021-06-30T18:27:55Z")

</div>

Err thats coz you are calling the channel rewards endpoint. That won’t return subscrubers

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 30, 2021, 6:32pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/51 "2021-06-30T18:32:09Z")

</div>

I do not want subscribers only channel rewards endpoint.

$ch = curl\_init(‘[https://api.twitch.tv/helix/channel\_points/custom\_rewards?broadcaster\_id=507703972](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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 30, 2021, 6:35pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/52 "2021-06-30T18:35:11Z")

</div>

If the response is blank, then that suggests there are no custom rewards available to return.

Assuming you didn’t get an error message.

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 30, 2021, 7:50pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/53 "2021-06-30T19:50:30Z")

</div>

$error = ‘Helix returned not one user’;

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [June 30, 2021, 7:52pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/54 "2021-06-30T19:52:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [June 30, 2021, 7:54pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/55 "2021-06-30T19:54:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [July 1, 2021, 10:36am UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/56 "2021-07-01T10:36:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 1, 2021, 10:38am UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/57 "2021-07-01T10:38:35Z")

</div>

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](https://barrycarlyon.co.uk/wordpress/2021/02/03/how-does-twitchs-new-eventsub-work/)

And: [Getting Tokens: OAuth | Twitch Developers](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow)

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)

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [July 1, 2021, 10:40am UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/58 "2021-07-01T10:40:24Z")

</div>

I’m going to see, thanks Barri

---

<div class="post-metadata">

**Author:** ![Ragnarok1978](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/ragnarok1978/32/12537_2.png) [@Ragnarok1978](https://discuss.dev.twitch.com/u/Ragnarok1978)\
**Post date:** [July 8, 2021, 7:23pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/59 "2021-07-08T19:23:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [August 8, 2021, 1:16pm UTC](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187/61 "2021-08-08T13:16:38Z")

</div>

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

[Previous page](https://discuss.dev.twitch.com/t/check-user-if-subscribed-to-my-channel/32187.md?page=2)
