Get user gives 401 error with working oauth

For my own amusement Im trying to create a C# library talking wiht the API and so far so good. I just struck a weird thing where my library will work when I do a GET request on api.twitch.tv/kraken?oauth_token=token with correct information, but if I try to go to api.twitch.tv/kraken/user?oauth_token=same token I get a 401 error. Now what strikes me as weird is that if I do a simple output of the URL I send the GET request to, copy/paste it to a browser without altering it, it works without any errors.
And to add to it I used the same URL on my roommates computer to demonstrate and ask for advice from him and on HIS computer MY Oauth token gives his account information.
So am I missing something stupidly obvious here?

using(var client = new HttpClient())
{
return await client.GetStringAsync(url);
}

This is the simple code I use to make the GET request, Which also is where the exception is thrown when I get the 401 error.

Shorter and cleaner version of question:
GET https://api.twitch.tv/kraken?oauth_token=*mytoken* works
GET https://api.twitch.tv/kraken/user?oauth_token=*mytoken* Throws exception in application because it returns 401, but works when accessed in my browser
Why is this?

Okay so I got it to work and realize I was using the wrong URL, so I want to change my question then to. Did it work in browser with the older URL because I was already logged in to my twitch account?

The 401 means the OAuth token doesn’t have the correct scope assigned (in this case, user_read scope). When you open the /user endpoint in the browser, it’s likely using the cookie of the logged in user.

1 Like

Yea figured it was something like that, just had to actually realize what I was doing wrong and it kind of made sense. Shouldve picked it up when my friends computer gave me his data instead of mine wiith my oauth token.
Thanks for clarifying! :slight_smile:

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