diff --git a/allstarr/Services/Spotify/SpotifyApiClient.cs b/allstarr/Services/Spotify/SpotifyApiClient.cs index c657cbc..774f2c8 100644 --- a/allstarr/Services/Spotify/SpotifyApiClient.cs +++ b/allstarr/Services/Spotify/SpotifyApiClient.cs @@ -28,7 +28,7 @@ public class SpotifyApiClient : IDisposable // Spotify API endpoints private const string OfficialApiBase = "https://api.spotify.com/v1"; private const string WebApiBase = "https://api-partner.spotify.com/pathfinder/v1"; - private const string TokenEndpoint = "https://open.spotify.com/get_access_token"; + private const string TokenEndpoint = "https://open.spotify.com/get_access_token?reason=transport&productType=web_player"; // Web API access token (obtained via session cookie) private string? _webAccessToken; @@ -99,14 +99,14 @@ public class SpotifyApiClient : IDisposable _logger.LogDebug("Fetching new Spotify web access token"); - var request = new HttpRequestMessage(HttpMethod.Get, TokenEndpoint); - request.Headers.Add("Cookie", $"sp_dc={_settings.SessionCookie}"); - - var response = await _webApiClient.SendAsync(request, cancellationToken); + // The cookie is already set in the CookieContainer during client construction + // No need to manually add Cookie header - HttpClient will handle it + var response = await _webApiClient.GetAsync(TokenEndpoint, cancellationToken); if (!response.IsSuccessStatusCode) { - _logger.LogError("Failed to get Spotify access token: {StatusCode}", response.StatusCode); + var errorBody = await response.Content.ReadAsStringAsync(cancellationToken); + _logger.LogError("Failed to get Spotify access token: {StatusCode} - {Body}", response.StatusCode, errorBody); return null; }