Get all subscribers

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

my code:

 $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

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

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?

  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

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

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

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