TwitchLib / TwitchLib.Api

API component of TwitchLib.
70 stars 84 forks source link

Helix API GetChattersAsync returning bad token exception #382

Closed WrithemTwine closed 10 months ago

WrithemTwine commented 10 months ago

I'm also experiencing the very same issue, Reference: Issue 343.

versioning image Target: .NET 8

(pseudocode explanation of credentials)


- I've validated the access token with api calls to get followers, clips, and channelinformation->category; so the token is getting data from Twitch. 
- also tried: "return await testChat.Helix.Chat.GetChattersAsync(channelId, moderatorId, accessToken: accesstoken );"-fail
- earlier (before isolating to above single Helix API instance test), switched access scope to the channel account & client id, and 'GetChatters' still failed with 'broadcaster_clientid & access token'
- I'm using the auth-code flow to refresh the access token on expiration.
- restarted visual studios, cleaned solution, short of rebooting my machine
- created a separate .NET 8 project 
     - only calling "Helix.Chat.GetChatters" and loading it into a GUI listbox (my main app is GUI based). 
     - https://github.com/WrithemTwine/TwineChatBot/blob/devfeature/SimpleTestFeature/Chatters.cs
     - be sure to use 'devfeature' channel
     - can download project to save code writing
     - need to provide all the Ids/token into the "chatters.cs" constructor <-entered my ids & token, still failed with bad scope exception

In a separate, "is this related?" note: when I created a TwitchApi instance to use in regular Helix calls and dropped it into the follower service (to use fewer instances where possible), the "GetAllFollowers" returned just the total followers count and not independent users (as in the call was invalidated). However, when I separated out Helix instances, a separate TwitchApi for follower service with the above token, the "GetAllFollowers" returned each follower to the channel.

I'm unsure why a TwitchApi instance would change from instantiation to cross-referencing, and a fresh TwitchApi instance permitted 'GetFollowers' to work. In parallel, can the same issue be why 'GetChatters" isn't working full-time? Though I tried a full fresh TwitchAPI instance and couldn't get GetChatters to work.
WrithemTwine commented 10 months ago

OK, I dug in some more to check what's happening.

When I manually get a token from: https://twitchapps.com/tokengen/, the broadcaster clientId and moderator client Id will properly access GetChatters.

For using refresh token and getting an access token in auth code flow, I checked the response and seeing an older list of scopes instead of the newer scope request. Unsure why (tied to clientId first time scopes are requested?).

Now verified correct scopes and GetChatters responds.

For anyone receiving the same error using Auth Code Grant Flow; I suggest when scopes change (say, have existing tokens, then add-on GetChatters call), clear access & refresh tokens and clear the auth code for the user to reauthenticate access-start the whole auth code grant flow process over again.