# Get all subscribers

**URL:** <https://discuss.dev.twitch.com/t/get-all-subscribers/40052>\
**Category:** API\
**Created:** [August 17, 2022, 1:12pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052 "2022-08-17T13:12:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AaronOrtega](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/aaronortega/32/19478_2.png) [@AaronOrtega](https://discuss.dev.twitch.com/u/AaronOrtega)\
**Post date:** [August 17, 2022, 1:12pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/1 "2022-08-17T13:12:00Z")

</div>

hey all, have a error: `"error" => "Unauthorized" "status" => 401 "message" => "Missing scope: channel:read:subscriptions or channel_subscriptions" ]`

my code:

```auto
 $client_id = 'id';
    $client_secret = 'secret';
    $url = 'https://id.twitch.tv/oauth2/token';
    $data = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'client_credentials', 'scope' => 'channel:read:subscriptions');

    $options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded\r\n",
            'method' => 'POST',
            'content' => http_build_query($data)
        )
    );

    $context = stream_context_create($options);
    $result = json_decode(file_get_contents($url, false, $context), true);
    if (isset($result['access_token'])) {
        $token = $result['access_token'];
        $curl = curl_init();

        curl_setopt_array($curl, [
                CURLOPT_URL => 'https://api.twitch.tv/helix/subscriptions?broadcaster_id=jankos',
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_TIMEOUT => 1,
                CURLOPT_HTTPHEADER => [
                    'Authorization: Bearer ' . $token,
                    'Client-Id: ' . $client_id
                ]
            ]
        );
        $res = json_decode(curl_exec($curl), true);

```

where is my fail? ty for answer

---

<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:** [August 17, 2022, 1:15pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/2 "2022-08-17T13:15:33Z")

</div>

`client_credentials` is not an approriate token for this endpoint\*

You need a user token representing the user you wish to read the subscriptions of.  
So you need to ask `jankos` to go to your website and login with Twitch and store the token

Additionally `jankos` is not the broadcasters ID but their login (use the ID returned from the Get Users Endpoint).

You have generated and used the wrong kind of oAuth token.

\*Except when the ClietnID is an extension and the extension is installed/active on the target channel

---

<div class="post-metadata">

**Author:** ![AaronOrtega](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/aaronortega/32/19478_2.png) [@AaronOrtega](https://discuss.dev.twitch.com/u/AaronOrtega)\
**Post date:** [August 17, 2022, 1:20pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/3 "2022-08-17T13:20:06Z")

</div>

ty, and if I want to get my subscribers, then…? I have to send an api request for login, take the key from it, right?

---

<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:** [August 17, 2022, 1:21pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/4 "2022-08-17T13:21:55Z")

</div>

1. Go to your website
2. Click login with Twitch
3. accept (or decline) the account linking between the ClientID and your Twitch Account
4. This normally retuns to your website with a `?code`
5. Exchange the `?code` for a token
6. Use “Get users” or “Validate Token” to get the user ID
7. User the userID and the token to call “Get Subscriptions”

This works the same regardless of which user you want subs for. First step is getting a USER token with the relevant scopes attached to said token. And the User providing positive linking

---

<div class="post-metadata">

**Author:** ![AaronOrtega](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/aaronortega/32/19478_2.png) [@AaronOrtega](https://discuss.dev.twitch.com/u/AaronOrtega)\
**Post date:** [August 17, 2022, 1:24pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/5 "2022-08-17T13:24:37Z")

</div>

But I don’t have a website where I can “log in via twitch”. My website is this code. which I have attached)

---

<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:** [August 17, 2022, 1:25pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/6 "2022-08-17T13:25:37Z")

</div>

Then you have no way to get a user token from `jankos`

Short of a temporary website via NGROK to get the token, but if the token dies you’ll need to reauth `jankos`

---

<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:** [September 16, 2022, 1:25pm UTC](https://discuss.dev.twitch.com/t/get-all-subscribers/40052/7 "2022-09-16T13:25:38Z")

</div>

Closed on September 16, 2022, 1:25pm UTC

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