A 401 means your token doesn’t have the correct scope attached to it. You can check to make sure your token has the correct scope by passing it to this URL: https://api.twitch.tv/kraken?oauth_token=
Also, just as an aside, the ?scope=channel_read on your URL doesn’t do anything for you.
Thanks for your answer.
So, I don’t need to add scope to my url? I added that before because I was getting HTTP Error 404: not found.
I just modified my url so it would look like:
Scope is defined when you’re generating an OAuth token as described in the authentication guide. I would highly recommend reading that and spend some time learning OAuth if you’re unfamiliar with it.
As stated in the documentation, https://api.twitch.tv/kraken/channel needs the channel_read scope. Your token, as you saw, only has the chat_login scope. You’ll need to generate a new token with the channel_read scope and pass that into your original code.
Your OAuth scopes will depend on which API endpoints or capabilities you’re using. For example, Get User uses user_read scope, Get Channel uses channel_read, chat uses chat_login scope. Each endpoint documents whether it requires a specific OAuth scope or not.
When you’re generating an OAuth token for a user, you should request only the smallest amount of scopes that you need to operate. A single token can have multiple scopes to it, but it’s up to you to request them when the user logs in.
Ok. Now I think I’m getting it. I created a new token with scope “channel_read”, I checked the scope in https://api.twitch.tv/kraken?oauth_token=mytoken and I saw scope is correctly defined.
But still, I am getting the Unauthorized error.