Reputation: 51
I am trying to get a list of users who are subscribed to a twitch channel through the twitch API, I have setup the request to get the access token and then I am calling the API /helix/subscriptions/ passing in the access token to get the list of subscribers, however I keep running into the same issue where I can't get a successful request.
Request failed with status code Unauthorized
var options = new RestClientOptions("https://id.twitch.tv/oauth2/token")
{
ThrowOnAnyError = true,
Timeout = 1000
};
var client = new RestClient(options);
var request = new RestRequest()
.AddQueryParameter("grant_type", "client_credentials")
.AddQueryParameter("client_id", clientId)
.AddQueryParameter("client_secret", clientSecret);
var response = await client.PostAsync(request);
var result = JsonConvert.DeserializeObject<OauthToken>(response.Content);
var userOptions = new RestClientOptions("https://api.twitch.tv/helix/subscriptions");
var clientR2 = new RestClient(userOptions);
var requestR2 = new RestRequest()
.AddHeader("Authorization", "Bearer " + result.access_token)
.AddHeader("Client-Id", clientId)
.AddQueryParameter("broadcaster_id", broadcasterId);
var responseR2 = await clientR2.GetAsync(requestR2);
I am not sure not if this is possible, I have gone over most of the twitch API documents and I've got a similar setup working with just getting "users", but subscriptions seems to not be working even with similar parameters.
Upvotes: 0
Views: 468
Reputation: 1058
You are using the wrong oAuth flow.
You need a token that representes a user, client_credentials
broadly speaking doesn't represent a user but a "server".
So with your token you do not have permission to read broadcasterId
subscriptions. Hence the 403/Request failed with status code Unauthorized
Read more on the official documentation here: https://dev.twitch.tv/docs/authentication#user-access-tokens
You need a response_type code
or token
not client_credentials
Upvotes: 1