# For Helix Subscriber Count

**URL:** <https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775>\
**Category:** API\
**Created:** [October 3, 2021, 3:39pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775 "2021-10-03T15:39:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 3:39pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/1 "2021-10-03T15:39:07Z")

</div>

How to get subscriber and followers count for my website ? i tried but not working. Can you example Any code used?

Old Code (For followers, Kraken it still works but it won’t work soon. ☹ )

$twitchlink = "[https://api.twitch.tv/kraken/channels/channel](https://api.twitch.tv/kraken/channels/channel) id ";

$twitchcurl = curl\_init($twitchlink);  
curl\_setopt($twitchcurl, CURLOPT\_URL, $twitchlink);  
curl\_setopt($twitchcurl, CURLOPT\_RETURNTRANSFER, true);

$twitchauth = array(  
“Accept: application/vnd.twitchtv.v5+json”,  
"Client-ID: (my client id) ",  
);  
curl\_setopt($twitchcurl, CURLOPT\_HTTPHEADER, $twitchauth);  
//for debug only!  
curl\_setopt($twitchcurl, CURLOPT\_SSL\_VERIFYHOST, false);  
curl\_setopt($twitchcurl, CURLOPT\_SSL\_VERIFYPEER, false);

$resp = curl\_exec($twitchcurl);  
curl\_close($twitchcurl);

$twitchveri = json\_decode($resp, true);  
$followers = $twitchveri[‘followers’];

echo $followers;

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 3:47pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/2 "2021-10-03T15:47:39Z")

</div>

You need to mgirate to Helix. Refer to the migration guide, it lists how a given kraken endpoint maps to a helix one:

[https://dev.twitch.tv/docs/api/migration](https://dev.twitch.tv/docs/api/migration)

for the subscribers count you will need permission from the broadcaster you wish to read subs from in order to read their subs.

For Subscribers

Get a user authentication token:

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

And loading a subscriber count

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

For followers: any sort of token will do

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

So since you want subscriber count you’ll use the broadcasters token to get both follower and sub count, so you won’t have to juggle two tokens.

So your code becomes (untested off the top of my head)

**Please note the added error checking of JSON and HTTP Status Codes.**

```php
<?php

$twitchlink = "https://api.twitch.tv/helix/users/follows?to_id=CHANNELID&first=1";

$twitchcurl = curl_init($twitchlink);
curl_setopt($twitchcurl, CURLOPT_URL, $twitchlink);
curl_setopt($twitchcurl, CURLOPT_RETURNTRANSFER, true);

$twitchauth = array(
"Client-ID: (my client id) ",
'Authorization: Bearer TOKENHERE'
);
curl_setopt($twitchcurl, CURLOPT_HTTPHEADER, $twitchauth);

$resp = curl_exec($twitchcurl);
$i = curl_getinfo($twitchcurl);
curl_close($twitchcurl);

if ($i['http_code'] == 200) {
    $twitchveri = json_decode($resp, true);
    if (json_last_error() == JSON_ERROR_NONE) {
        $followers = $twitchveri->total;
        echo $followers;
    } else {
        echo 'Failed to Parse JSON';
    }
} else {
    echo 'Failed with ' . $i['http_code'];
}

```

This should also work for subscribers (since using the broadcasters sub token), calling

`https://api.twitch.tv/helix/subscriptions?broadcaster_id=CHANNELID&first=1`

Instead and extracting `total` the same way.

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 3:56pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/3 "2021-10-03T15:56:21Z")

</div>

> [@BarryCarlyon](#):
>
> This should also work for subscribers (since using the broadcasters sub token), calling
> 
> `https://api.twitch.tv/helix/subscriptions?broadcaster_id=CHANNELID&first=1`
> 
> Instead and extracting `total` the same way.

This is not work. i edited user id, token and client id.  
Error text;  
Failed with 401

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 3:57pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/4 "2021-10-03T15:57:54Z")

</div>

> [@kurinshikari](#):
>
> Failed with 401

This indicates you used a token that is likely not valid to call subscriptions with

Change:

> echo 'Failed with ’ . $i[‘http\_code’];

to

> echo 'Failed with ’ . $i[‘http\_code’] . ’ - ’ . $resp;

And it’ll spit out the error

You need a user token that belongs to `CHANNELID` with the scope `channel:read:subscriptions` applied to it

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 4:35pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/5 "2021-10-03T16:35:24Z")

</div>

iam having an authorization problem.

```auto
Failed with 401 - {"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}

```

I’m trying to pull data for my own channel. I created cliend id, secret code.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 4:43pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/6 "2021-10-03T16:43:26Z")

</div>

> [@kurinshikari](#):
>
> I’m trying to pull data for my own channel. I created cliend id, secret code.

You need to generate a token.

The Client Secret is not a token.  
This error sounds like you used your clientSecret as token.  
The secret is not a token.

You will need to use your ClientID and Secret to create a webpage to fetch and generate a token with the scope `channel:read:subscriptions` applied

As covered in this documentation:

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 4:57pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/7 "2021-10-03T16:57:48Z")

</div>

> [@BarryCarlyon](#):
>
> You need to generate a token.
> 
> The Client Secret is not a token.  
> This error sounds like you used your clientSecret as token.  
> The secret is not a token.
> 
> You will need to use your ClientID and Secret to create a webpage to fetch and generate a token with the scope `channel:read:subscriptions` applied
> 
> As covered in this documentation:

I can’t understand what is explained in the document. I’m about to eat my head.Isn’t token generated from developer console? I can’t find the token. 😡 😡

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 5:03pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/8 "2021-10-03T17:03:00Z")

</div>

> [@kurinshikari](#):
>
> I’m about to eat my head.Isn’t token generated from developer console?

No the token is not generated fron the console.

A given application doesn’t auto grant rights to a users account.

> [@kurinshikari](#):
>
> I can’t find the token

There is no Token to find as it’s not there.

> [@kurinshikari](#):
>
> I can’t understand what is explained in the document.

This is the oAuth flow in a nutshell:

- Create a webpage with a link as in `<a href="">Login With Twitch</a>`
- This will be a link to Twitch along the lines of:

`https://id.twitch.tv/oauth2/authorize?client_id=CLIENTID&redirect_uri=URLENCODEDRETURLINK&response_type=code&scope=channel:read:subscriptions`

- The user you want to read subscribers of will click this link
- The user is then asked if they wish to allow `CLIENTID` access to their account.
- The user click yes/no
- If yes, the user is then rediredrect back to `RETURNLINK` with a `?code` in the URL
- The webpage at `RETURNLINK` then will do a POST request to Twitch to exchange that `code` for an access token (and a refresh token).

That access token can then be used to do sub data lookups. You will need to store the refresh token so you can get a new access token when the access token expires

This is a “one page” example in PHP that will do “regular/refreshable” User authentication that should serve as an example to build you own flow for this [https://github.com/BarryCarlyon/twitch\_misc/tree/main/authentication/user\_access\_generator/php](https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/user_access_generator/php)

And example includes a script to maintain that token.

But you’ll need to determine where you store the token/refresh token for use and adjust accordingly.

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 5:16pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/9 "2021-10-03T17:16:07Z")

</div>

> [@BarryCarlyon](#):
>
> [https://id.twitch.tv/oauth2/authorize?client\_id=CLIENTID&redirect\_uri=URLENCODEDRETURLINK&response\_type=code&scope=channel:read:subscriptions](https://id.twitch.tv/oauth2/authorize?client_id=CLIENTID&redirect_uri=URLENCODEDRETURLINK&response_type=code&scope=channel:read:subscriptions)

The ones my made on what you sent. (github) 🤔  
{“status”:400,“message”:“invalid client”}

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 5:16pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/10 "2021-10-03T17:16:45Z")

</div>

You need to substitute the CLIENTID for a valid ClientID.

This error suggests the ClientID you provided was invalid

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 5:42pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/11 "2021-10-03T17:42:20Z")

</div>

There are 3 different client ids that I created. I’m getting the same error on all of them.  
Since I am a new member, it does not allow me to share screenshots.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 5:43pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/12 "2021-10-03T17:43:37Z")

</div>

What is the outbound `<a href=""` you have created?

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 5:55pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/13 "2021-10-03T17:55:39Z")

</div>

I just want to take the data of my own channel and publish it on my website.It shouldn’t be this hard! Why am I still having problems even though I have given the necessary permissions through the console. It’s so silly.

`https://id.twitch.tv/oauth2/authorize?client_id=(ClientID)&redirect_uri=(MyWebSite)&response_type=code&force_verify=false&state=D1f3%2BNV1N2vlnw%3D%3D&scope=`  
I have authorized via this link. And the authorization I have given in the Account Settings - Connections section of my channel is visible.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 5:58pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/14 "2021-10-03T17:58:00Z")

</div>

`(ClientID)` is not a valid clientID. Hence the error…

There is no need to hide a clientID, as they are considered public.

> [@kurinshikari](#):
>
> Why am I still having problems even though I have given the necessary permissions through the console

There isn’t a permissions system in the console. Not sure to what you refer.

> [@kurinshikari](#):
>
> There are 3 different client ids that I created. I’m getting the same error on all of them.

Which step is resulting in the error, oAuth or subdata fetching? Just to clarify

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 3, 2021, 8:54pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/15 "2021-10-03T20:54:00Z")

</div>

> [@BarryCarlyon](#):
>
> `(ClientID)` is not a valid clientID. Hence the error…
> 
> There is no need to hide a clientID, as they are considered public.

Does it create any security vulnerability if I share the Client ID with you?

> [@BarryCarlyon](#):
>
> There isn’t a permissions system in the console. Not sure to what you refer.

The permission I am talking about is not on the console.I can view it in my twitch account as an authorized client ID.

> [@BarryCarlyon](#):
>
> Which step is resulting in the error, oAuth or subdata fetching? Just to clarify

I can’t create a token. Or I can’t access the token I created.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2021, 10:35pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/16 "2021-10-03T22:35:20Z")

</div>

> [@kurinshikari](#):
>
> Does it create any security vulnerability if I share the Client ID with you?

No. ClientID’s are considered public as they show in the URL when people authenticate.

> [@kurinshikari](#):
>
> I can’t create a token. Or I can’t access the token I created.

Which step of the flow is failing?

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 4, 2021, 6:25pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/17 "2021-10-04T18:25:39Z")

</div>

Should I create tokens via twitchtokengenerator com? I cannot create any other tokens.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 4, 2021, 6:27pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/18 "2021-10-04T18:27:13Z")

</div>

You shouldn’t use other peoples token generators.

You should build/utilize your own.

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 4, 2021, 6:29pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/19 "2021-10-04T18:29:52Z")

</div>

I can’t do it myself. I couldn’t create a token no matter what I did. I have no clue how to proceed.Can you help on any platform like Discord or etc.?

---

<div class="post-metadata">

**Author:** ![kurinshikari](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/kurinshikari/32/13768_2.png) [@kurinshikari](https://staging-discuss.dev.twitch.com/u/kurinshikari)\
**Post date:** [October 4, 2021, 9:49pm UTC](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775/20 "2021-10-04T21:49:55Z")

</div>

![image](https://d2spem0quai2ol.cloudfront.net/original/2X/3/379398bc3a931a0a8f2a23ba520b893bbadc56c7.png)

The token I created through the Twitch generator is only 1 day old. Can you help me create a permanent token?

> [@BarryCarlyon](#):
>
> This is a “one page” example in PHP that will do “regular/refreshable” User authentication that should serve as an example to build you own flow for this [twitch\_misc/authentication/user\_access\_generator/php at main · BarryCarlyon/twitch\_misc · GitHub](https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/user_access_generator/php)

I logged in as you posted this.

[Next page](https://staging-discuss.dev.twitch.com/t/for-helix-subscriber-count/33775.md?page=2)
