# Check if user is subscriber

**URL:** <https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457>\
**Category:** API\
**Created:** [December 12, 2020, 1:30am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457 "2020-12-12T01:30:07Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 1:30am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/1 "2020-12-12T01:30:07Z")

</div>

Hi,

Unfortunately, I can’t get any further.

Users can log in to my website using the TwitchLogin.

The login works perfectly according to this pattern:

MY WORKFLOW

1. Click on the button ([https://id.twitch.tv/oauth2/authorize](https://id.twitch.tv/oauth2/authorize))
2. Get Code
3. Get Token from [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token)
4. Get user data with tokens from [https://api.twitch.tv/helix/users](https://api.twitch.tv/helix/users)

But now I would like to check whether the user is a subscriber in my channel.

After hours of searching on Google and here in the forum, I only found the information that I can only read all subscribers from my channel via [https://api.twitch.tv/helix/subscriptions?broadcaster\_id=XXXXXXXX](https://api.twitch.tv/helix/subscriptions?broadcaster_id=XXXXXXXX)

However, that doesn’t do me any good, as I only get this information when I click the login button and a token is generated for me.

But the user clicks the login button and then receives a token for himself.

Do I now have to log in every day in order to save the subscribers in my database and check them each time the user logs in?

It should also go over the old API V5 (Kraken). However, this somehow doesn’t work in my process.

I had tried this in my workflow (tokens etc. above): [https://api.twitch.tv/kraken/users/#USERID#/subscriptions/#CHANNELID#](https://api.twitch.tv/kraken/users/#USERID#/subscriptions/#CHANNELID#)

But then do I only get an empty array back?

Can someone help me and tell me where the problem is?

I know you probably post links to the docs of the API V5 and the new Api. Please don’t do that, I already know all of them from all other forum posts and from all stackoverflow posts. That doesn’t get me any further as I seem to have a mistake in my thoughts somewhere.

Many Thanks!

---

<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:** [December 12, 2020, 3:31am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/2 "2020-12-12T03:31:40Z")

</div>

Step 1) Setup an oAuth loop to get a token for yourself that will read subscribers  
Step 2) Store that token and the refresh token in a database  
Step 3) user logs into your website as them  
Step 4) use the users token to get their user ID  
Step 5) call the subscribers API with their userID and your userID (as the broadcasterID) **but your oAuth token** that you load up from the database.

You would store your oAuth token (and refresh token) in a database and recall it/refresh it as needed.

You have all the right parts. You just didn’t connect the dots.

The token you generate for yourself will be valid for four hours, but because you have a refresh token, you can refresh it as needed whenever you need it. Then store the new token back in the database for later use.

> [@TwitchEntwickler](#):
>
> Do I now have to log in every day in order to save the subscribers in my database and check them each time the user logs in?

No you just have to login/create your oAuth token with subscriber access whenever the refresh token procedure fails, which should only be if you disconnect your own app, or your reset your password.

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 6:59pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/3 "2020-12-12T18:59:51Z")

</div>

Hi,

what a great answer. Thank you very much!

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 9:26pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/4 "2020-12-12T21:26:39Z")

</div>

> [@BarryCarlyon](#):
>
> subscribers API

Hi Barry,

I still have an important question and I hope you can help me.

Do I have to get a new token here [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token) (start new call) every time I query [https://api.twitch.tv/helix/subscriptions](https://api.twitch.tv/helix/subscriptions)? Or can i only use the token from login via [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token) from database? Can I call [https://api.twitch.tv/helix/subscriptions](https://api.twitch.tv/helix/subscriptions) again and again until the token has expired?

I am asking because I am now getting a 401 error. When I call [https://api.twitch.tv/helix/subscriptions](https://api.twitch.tv/helix/subscriptions) from the broadcaster with the token and ClientID.

My Code:

```
$curl = curl_init('https://api.twitch.tv/helix/subscriptions?broadcaster_id='.$broadcasterClientID);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'Client-ID: ' . $broadcasterClientID,
      'Authorization: Bearer ' . $broadcasterToken
  ));
  curl_setopt($curl, CURLOPT_TIMEOUT, 1000);    

```

Many Thanks!

---

<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:** [December 12, 2020, 9:39pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/5 "2020-12-12T21:39:55Z")

</div>

> [@TwitchEntwickler](#):
>
> Can I call [https://api.twitch.tv/helix/subscriptions](https://api.twitch.tv/helix/subscriptions) again and again until the token has expired?

Yes.

> [@BarryCarlyon](#):
>
> The token you generate for yourself will be valid for four hours, but because you have a refresh token, you can refresh it as needed whenever you need it. Then store the new token back in the database for later use.

When the token expires, use the refresh token to get a new token

> **[Authentication](https://dev.twitch.tv/docs/authentication/#refreshing-access-tokens)**
>
> Authentication

> [@TwitchEntwickler](#):
>
> I am asking because I am now getting a 401 error

Read the body message of the response it’ll tell you the problem.

HTTP Code’s are useless without the body messages from the response

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 10:09pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/6 "2020-12-12T22:09:17Z")

</div>

Ok, thanks for the info.

Oops, forgot the body. I get this information:

{“error”:“Unauthorized”,“status”:401,“message”:“Client ID and OAuth token do not match”}

The ClientID is the ID that I got back from the login as the id in the object.

An idea?

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 10:13pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/7 "2020-12-12T22:13:04Z")

</div>

Ah no stop it all back. The ClientID is of course the ID of the Twitch application. I think that’s the mistake.

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 10:18pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/8 "2020-12-12T22:18:29Z")

</div>

Ok that was the problem. I am stupid ^^  
Do i only get 20 subscribers? In Doc there are two parameters first and after. But how are these to be used as parameters in the url?

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 10:27pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/9 "2020-12-12T22:27:28Z")

</div>

Aaah ok, so you can use the following (for everyone who has the same problem)

20 results  
[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID](https://api.twitch.tv/helix/subscriptions?broadcaster_id=%24broadcasterID)

100 results  
[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&first=100](https://api.twitch.tv/helix/subscriptions?broadcaster_id=%24broadcasterID&first=100)

Specifically a user  
[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&user\_id=$user\_twitchID](https://api.twitch.tv/helix/subscriptions?broadcaster_id=%24broadcasterID&user_id=%24user_twitchID)

But what is the parameter After?

[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&after=100](https://api.twitch.tv/helix/subscriptions?broadcaster_id=%24broadcasterID&after=100)

[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&after=1](https://api.twitch.tv/helix/subscriptions?broadcaster_id=%24broadcasterID&after=1)

don’t work. But why?

---

<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:** [December 12, 2020, 10:36pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/10 "2020-12-12T22:36:02Z")

</div>

`after` uses the value of `pagination->cursor`

For example

 ![image](https://d2opxh93rbxzdn.cloudfront.net/original/2X/2/25aa128fe964c768cc3c7b5feb9522931841f985.png)

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 10:39pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/11 "2020-12-12T22:39:53Z")

</div>

> [@TwitchEntwickler](#):
>
> [https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&after=1](https://api.twitch.tv/helix/subscriptions?broadcaster_id=$broadcasterID&after=1)

aah ok so i use it like:  
[https://api.twitch.tv/helix/subscriptions?broadcaster\_id=$broadcasterID&after=eyJiIjp](https://api.twitch.tv/helix/subscriptions?broadcaster_id=$broadcasterID&after=eyJiIjp)… ?

---

<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:** [December 12, 2020, 10:55pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/12 "2020-12-12T22:55:23Z")

</div>

Correct

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 12, 2020, 11:29pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/13 "2020-12-12T23:29:17Z")

</div>

Hey barry,

do you know whether it is possible to read a user’s follower date? Or is that not possible via the API?

Thank you !

---

<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:** [December 13, 2020, 12:42am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/14 "2020-12-13T00:42:36Z")

</div>

Thats included in

> **[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.

Example

```auto
{
   "total": 12345,
   "data":
   [
      {
         "from_id": "171003792",
         "from_name": "IIIsutha067III",
         "to_id": "23161357",
         "to_name": "LIRIK",
         "followed_at": "2017-08-22T22:55:24Z"
      },
      {
         "from_id": "113627897",
         "from_name": "Birdman616",
         "to_id": "23161357",
         "to_name": "LIRIK",
         "followed_at": "2017-08-22T22:55:04Z"
      },
      ...
   ],
   "pagination":{
     "cursor": "eyJiIjpudWxsLCJhIjoiMTUwMzQ0MTc3NjQyNDQyMjAwMCJ9"
   }
}

```

You can specify a `from_id` (user) and `to_id` (broadcaster) to get the date that `somesuer` followed `lirik` on Twitch. (Names for example to illustrate relationship)

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 13, 2020, 1:07am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/15 "2020-12-13T01:07:01Z")

</div>

Thank you very much!

So I have to go through all followers to see if a user followed. I can’t search for the UserID directly, right?

---

<div class="post-metadata">

**Author:** ![TwitchEntwickler](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@TwitchEntwickler](https://discuss.dev.twitch.com/u/TwitchEntwickler)\
**Post date:** [December 13, 2020, 1:09am UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/16 "2020-12-13T01:09:51Z")

</div>

Ah ok i see i can use both params nice !

[https://api.twitch.tv/helix/users/follows?from\_id=$user\_userid&to\_id=$masterBroadcasterID](https://api.twitch.tv/helix/users/follows?from_id=%24user_userid&to_id=%24masterBroadcasterID)

---

<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:** [December 13, 2020, 12:31pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/17 "2020-12-13T12:31:24Z")

</div>

> [@BarryCarlyon](#):
>
> You can specify a `from_id` (user) and `to_id` (broadcaster) to get the date that `somesuer` followed `lirik` on Twitch. (Names for example to illustrate relationship)

> [@TwitchEntwickler](#):
>
> Ah ok i see i can use both params nice !

I did say _and_ 😃

Edit: you can also to/from Pairs for the subscribers/banned endpoints etc

---

<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:** [January 12, 2021, 12:31pm UTC](https://discuss.dev.twitch.com/t/check-if-user-is-subscriber/29457/18 "2021-01-12T12:31:31Z")

</div>

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