Im trying to build a twitch bot with help of google etc. But Im getting
API Status Code: 401
API Response: {“error”:“Unauthorized”,“status”:401,“message”:“Invalid OAuth token”}
Error while fetching moderators. Status Code: 401
When trying to get moderators with the API. I am 100% sure OAuth token is correct and its not expired. I am trying to make !addcmd to only mods and I cant get it to work. And I think the biggest issue is that I cant get the API to work.
What could it be, why is it Unauthorized if I know that the OAuth is correct and so is the Client_id?
You did generate an oAuth token and are not trying to use your client secret as a token? And you also have created a user access token and not a client credentials token?
The usual flow is this one
And that token’s user ID is the channel you are trying to read the moderators of?
The Get Moderators API will require a user token with moderation:read or channel:manage:moderators (usually the former scope)
And if I want to read fred moderators I need a token from fred
I have generated an OAuth token with the help from the Client ID token I got from creating the “app” on dev.twitch.tv and I am not using the client secret.
What do you mean by user access token? You dont mean the client id I m getting from the app page?
I do have those scopes in that generated OAuth token yes.
Hmm, have I missunderstood completelty, the CLIENT_ID in the code, should be the channel Im connecting to and not the apps client id? Holy shit, Im getting confused now
The channel you want to read the moderators of, has to login with twitch with your client ID.
So the streamers needs to grant permission to your client to read moderators
Who owns the clientID is irrelevant.
So I have a client ID foo
If I want to read cohhcarnage’s moderators, I ask cohhcarnage to go to my website and login with Twitch, granting the relevant scopes.
So cohhcarnage creates a link between his account and my clientID
Then I use the resultant oAuth token to read cohhcarnage’s moderators.
cohhcarnage does not have to create his own clientID.
Just needs to gran access to my clientID to his account
A user access token is generated from clientID/clientsecret/user interaction set
user clicks on “Connect with Twitch” in this case the “New/Refresh Broadcaster Login” button, as this is the “main scopes set” link for my chatbot
user is sent to Twitch
user accepts (or declines) the link request betwee their account and my clientID.
user is redirected back to my website
I grab the ?code and with the client secret, exchange it for an access token and refresh token.
That in a nutshell is how oAuth works.
This sounds like you generated a client credentials token aka app access token which doesn’t represent a Twitch user. So cannot be used to call “Get Channel Moderators”
But the client id I put in is from the app, so thats wrong? How do I know what client id I should say?
And if I had the correct client id, with the correct scopes, I get an access_token wich is my OAuth key, correct?
Sorry for beeing slow but well, I just started, duuh
Alright lets see if I have understood correct:
1 Create app and get the client ID
2 Go to the website that I linked before with the client ID and correct scopes
3 Then I get the OAuth
But you said I should use the app client id but I cant really find any else?
Yeah, so I have had the correct client id all the time.
so when I have generated that oauth key, what “url” do I open with my streamer account, not the bot account.
Trying to: https://id.twitch.tv/oauth2/token
client_id=The Client ID
&client_secret=The Client secret
&code=The code I got from the first url
&grant_type=authorization_code
&redirect_uri=https://localhost