Trying to get channel's subscriptions only gives error

ok, so i have a method to getting a new twitch token through code, it looks like this

const url = "https://id.twitch.tv/oauth2/token?client_id=TWITCH_ID&client_secret=TWITCH_SECRET&grant_type=client_credentials&scope=channel:read:subscriptions"
const res = await axios.post(url);
return res.data.access_token;

and this gives me a token just fine, gives me the correct scopes.

but when I’m trying to get a channel’s subscriptions, it gives me this error:

{
      error: 'Unauthorized',
      status: 401,
      message: 'Invalid OAuth token'
}

what am I doing wrong? how do I do this?

client_credentials is not a valid token type to call subscriptions with*

You need a user access token

a client_credentials doesn’t represent a user so it doesn’t have authority to read subscribers

*unless it’s an extension clientID with sub capabilities enabled.

ok… so it gives me this example

POST https://id.twitch.tv/oauth2/token
    ?client_id=uo6dggojyb8d6soh92zknwmi5ej1q2
    &client_secret=nyo51xcdrerl8z9m56w9w6wg
    &code=394a8bc98028f39660e53025de824134fb46313
    &grant_type=authorization_code
    &redirect_uri=http://localhost

so what do I set as the code header? it seems like it has something to do with the redirect uri, but since my application is just getting a channel’s information, it wont redirect users. what do I do here?

For regular user oAuth

  1. Generate a URL
  2. Redirect the user to that URL
  3. They accept (or decline) allowing access to their account to your Client ID
  4. They return to your website with a code (or error message)
  5. Exchange the code for an access token (using the post request you posted)

To get subscriber data you need permission from the broadcaster, which will require this “oAuth loop” to get delegated access.

ok so i need permission from the channel… is there a way to: instead of getting the list of subscribers of a channel, get the number of subs? because i want to be able to get the subscriber count of any channel. is this possible?

No

Subscriber data is “priviledged” information.

You require permission from the owner of that data to read that data.

ok, that makes sense. thanks for taking time to answer this, I appreciate it : )

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