Fix Spotify token endpoint - add required query params and fix cookie handling

This commit is contained in:
2026-02-03 14:22:51 -05:00
parent 1532d74a20
commit 590f8f76cb

View File

@@ -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;
}