In my application there are several methods using the Twitch API, I will give an example of one of them:
private async Task<TwitchStreamResponse> GetStreamInfo(string channel)
{
var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.twitch.tv/helix/streams?user_login={channel}");
request.Headers.Add("Client-ID", _clientId);
request.Headers.Add("Authorization", $"Bearer {_accessToken}");
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TwitchStreamResponse>(responseBody);
}
Error example:
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Connection: keep-alive
Timing-Allow-Origin: https://www.twitch.tv
Date: Tue, 23 Jul 2024 22:43:28 GMT
X-Served-By: cache-bfi-kbfi7400042-BFI, cache-ams21070-AMS
X-Cache: MISS, MISS
X-Cache-Hits: 0, 0
X-Timer: S1721774608.133008,VS0,VS0,VE153
Vary: Accept-Encoding
Vary: Origin
Strict-Transport-Security: max-age=300
Content-Length: 69
Content-Type: application/json; charset=utf-8
}
I didn’t change anything in the code, but at some point these methods started returning a 401 Unauthorized error.
I tried to create a new app in the twitch api console and use the new Client-ID and Authorization headers, but it did not help.
Could you tell me, please, maybe something has changed in using the API? I didn’t find any information and I can’t understand why this problem started to appear.