Need some help with auth tokens [TwitchLib]

I’m trying to make a simple API call to get the subs to my channel.

		ApiSettings aps = new ApiSettings();
		aps.ClientId = "<client ID>";
		aps.AccessToken = "<auth token>";
		aps.Scopes = new List<AuthScopes>(){AuthScopes.Helix_Channel_Read_Subscriptions};
		Subscriptions s = new Subscriptions(aps, TimeLimiter.GetFromMaxCountByInterval(100, TimeSpan.FromSeconds(1)), new TwitchHttpClient());
		Task<GetBroadcasterSubscriptionsResponse> subTask = s.GetBroadcasterSubscriptions("zoliking");
		GetBroadcasterSubscriptionsResponse gbsr = await subTask;
		subs = gbsr.Data;

Now here’s my issue: When I plugged in the authorization token I got from twitchtokengenerator that I used for my credentials for initializing a TwitchClient object, I got an exception saying it has the wrong scopes, even though all Helix scopes were selected when I generated it. I then tried generating a new token that only had the channel:read:subscriptions scope and use that, it didn’t work. I tried switching out the client ID from my app’s to the one twitchtokengenerator displayed alongside the generated token. I tried using the token with the fewer scopes for both the TwitchClient and the API call. That broke the TwitchClient part as well. Meanwhile I noticed that the scopes in TwitchLib don’t even correspond to the ones in twitchtokengenerator in a 1:1 fashion.
Can somebody explain these tokens to me like I was a mentally challenged child?

EDIT: Apparently the issue is that I’m feeding in the wrong argument for broadcaster_id. Can anybody let me know how to find the broadcaster_id using TwitchLib?

First off, don’t use 3rd party sites to generate tokens as they can’t be refreshed so every time the token expires you’ll have to go through the whole process over again, and there’s an inherent security risk of using some other developers OAuth flow who’s not associated with Twitch.

If you’re making requests server-side, use the Authorization Code Flow
If you’re making requests client-side (such as in a web browser), use the Implicit Flow

Secondly, in your call to GetBroadcasterSubscriptions you’re passing the accounts login, ie "zoliking", but the API request requires broadcaster_id to be the accounts id, so you’re passing in the wrong thing.

That page was about the first thing I saw when I started doing research on how to do this and it means nothing to me. As far as I can tell it discusses http requests of some kind without providing any context about what the hell is going on. It’s seems like a reference material for people who know exactly how the system works and need specific details on a given step, it’s not “explaining these tokens to me like I was a mentally challenged child”.
It also offers no explanations on why the tokens used ended up producing a an exception regarding the scopes.
The broadcaster_id thing is a valid point. I looked high and low trying to find a separate broadcaster_id associated with my account, but couldn’t find it, so I figured I’d just try the username instead. How do I get the broadcaster_id?

OAuth 2.0 is an industry standard, so the Twitch documentation provides the step by step instructions on how to make the requests to their OAuth endpoints. If you wish to look more in depth, or for more generic guides on OAuth2, I suggest searching for it online as there is a wealth of information available as well as the official RFC for the specification.

It’s rare, but some endpoint return a wrong error reason when they are passed malformed data (such as trying to use a login in place of an id). Also if you’re using a library such as you are instead of making the API requests yourself there it could be the library is mistakenly displaying an error, or is an issue with that depending on if it passes you the error directly from Twitch or if it uses its own error messages.

You can use the Get Users, or Validate Token endpoints with your OAuth token, and it will return the user associated with that token, including their id.

Your explanation on why I might be getting the error I’m getting makes sense, thank you.

If you want some additional information on OAuth 2.0, feel free to refer to the resources linked in this FAQ Post: (disclaimer: I wrote it.) Authenticating with the Twitch API

The really short version of it is: User authorizes your app to access the details of their account and then you can access that information.

I’m not looking for information on OAuth 2.0, thank you. I’m looking to solve my problem with the library I have.

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