SpotifyAPI-NET icon indicating copy to clipboard operation
SpotifyAPI-NET copied to clipboard

What happened to SetShuffle, SetRepeat, SkipNext and maybe more??

Open FrankBJensen opened this issue 1 year ago • 10 comments

Hi.

Happy user of the API, running in a C# windows enviroment, using latest 7.1.1, .net and .net framework 4.8.1. I have same program running on several machines, and I updated my code to ver. 7 looong time ago, and it has been running quite nicely since.

But a couple of days ago, some calls have been failing, and I am not quote sure why. Has something been changed??

shuffle = await spotify.Player.SetShuffle(new PlayerShuffleRequest(true) { DeviceId = deviceID }); repeat = await spotify.Player.SetRepeat(new PlayerSetRepeatRequest(PlayerSetRepeatRequest.State.Context) { DeviceId = deviceID }); await spotify.Player.SkipNext(new PlayerSkipNextRequest() { DeviceId = deviceID } ); and there might be more, havent tested them all

results in a Exception thrown: 'Newtonsoft.Json.JsonReaderException' in mscorlib.dll An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in mscorlib.dll but was not handled in user code Unexpected character encountered while parsing value: k. Path '', line 0, position 0

Does anyone else have this problem? How can I resolve this?

FrankBJensen avatar Jul 12 '24 17:07 FrankBJensen

I have the same issue, no luck in solving it.

Xslash58 avatar Jul 14 '24 05:07 Xslash58

Hi,

Do the endpoints work in the web api console? Can you also give the whole stack trace?

JohnnyCrazy avatar Jul 14 '24 06:07 JohnnyCrazy

Hi Johnny.

I am on vacation, and right now my teamviewer do not connect to my home station... :-/ But I might be able to get the complete log entry from windows, I do not know if that contains what you need. I will check the web api console later.

Additional info:

This call is also throwing same error: await spotify.Player.PausePlayback(new PlayerPausePlaybackRequest() { DeviceId = deviceID } );

However, this call is NOT, and working as usual playing = await spotify.Player.ResumePlayback(new PlayerResumePlaybackRequest() { DeviceId = deviceID, ContextUri = param1, OffsetParam = new PlayerResumePlaybackRequest.Offset { Uri = param2 } });

So I am able to start playing a song, get artist info, play state and so, but not to pause it. I have a feeling that Spotify changed the syntax or expects some more parameters for some API calls.

FrankBJensen avatar Jul 14 '24 06:07 FrankBJensen

I'll also add here that for (at least) me this works but throws an error. I mean for example the await spotify.Player.SkipNext(); will throw an error, but the spotify client will skip the song.

The error is:

Newtonsoft.Json.JsonReaderException: Error parsing boolean value. Path '', line 1, position 1. at Newtonsoft.Json.JsonTextReader.ParseTrue() at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at SpotifyAPI.Web.Http.NewtonsoftJSONSerializer.DeserializeResponse[T](IResponse response) at SpotifyAPI.Web.Http.APIConnector.DoSerializedRequest[T](IRequest request, CancellationToken cancel) at SpotifyAPI.Web.Http.APIConnector.SendAPIRequestDetailed(Uri uri, HttpMethod method, IDictionary`2 parameters, Object body, IDictionary`2 headers, CancellationToken cancel) at SpotifyAPI.Web.Http.APIConnector.Post(Uri uri, IDictionary`2 parameters, Object body, CancellationToken cancel) at SpotifyAPI.Web.PlayerClient.SkipNext(CancellationToken cancel) at TurtegBot.Commands.Spotify.skip.InvokeAsync(CommandProps props) in C:\Users\kapim\source\repos\turtegbot\TurtegBot\Commands\Spotify\skip.cs:line 29

Xslash58 avatar Jul 14 '24 10:07 Xslash58

Hi again.

I can confirm, that catching - and ignoring - the exception actually works for SetShuffle, SetRepeat, SkipNext and PausePlayback - the calls do what they are supposed to do.

So the API seems to work, except the the faulty exception.

The exception text is not quite the same for these 4, but they are all Unexpected character encountered while parsing.

FrankBJensen avatar Jul 14 '24 16:07 FrankBJensen

I think the problem is that the Spotify team has changed the API

A similar issue in the TypeScript client: https://github.com/spotify/spotify-web-api-ts-sdk/issues/119

drajwer avatar Jul 15 '24 14:07 drajwer

Thought so, we had this happen twice in the last year. Let's see if they will fix this short term

JohnnyCrazy avatar Jul 15 '24 14:07 JohnnyCrazy

Is there anywhere we can follow/push on this issue with Spotify? I can remove the feature from my app for now but would like to be able to reinstate it in the future

Epiphane avatar Jul 20 '24 01:07 Epiphane

Yea that's the other problem. They basically don't have any public relations since the layoffs/this year.

https://x.com/SpotifyPlatform is basically dead, last engagement was last year https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer is completely ignored. Bugs reported there get no answer or resolution. See this example https://status.spotify.dev/ is down since last year too

Can't understand how a platform with 615 million users:

  • is returning non-JSON responses in a JSON API (integration tests? canaries?)
  • is unable to detect and fix the issue in over 7 days
  • does not provide any way to report feedback/bugs.

My 2 cents, Spotify does not care about this API anymore and it's basically running on maintance mode with barely any resources to work on it.

For now, I'm not yet convinced adding non-JSON response parsers is the way to go, spotify needs to fix this. If you just want it to work, wrap the call in a try-catch and ignore the response parsing error.

JohnnyCrazy avatar Jul 20 '24 22:07 JohnnyCrazy

I've implemented a workaround using custom JSON serializer. It might be easier if you have many calls to these unhealthy endpoints.

public class JsonSerializerDecorator : IJSONSerializer
{
    private readonly NewtonsoftJSONSerializer _jsonSerializer = new();

    public void SerializeRequest(IRequest request)
    {
        _jsonSerializer.SerializeRequest(request);
    }

    public IAPIResponse<T> DeserializeResponse<T>(IResponse response)
    {
        try
        {
            return _jsonSerializer.DeserializeResponse<T>(response);
        }
        catch (JsonReaderException)
        {
            return new APIResponse<T>(response);
        }
    }
}

Usage:

    var config = SpotifyClientConfig.CreateDefault()
        .WithJSONSerializer(new JsonSerializerDecorator());
        
    var spotify = new SpotifyClient(config);

drajwer avatar Jul 23 '24 19:07 drajwer

Hi,

I just published 7.2.0 to potentially fix the issue. Changed the following:

  • Only parse JSON if the content-type header is explicitly set to application/json. This should prevent the parsing errors we've seen for those weird endpoints.
  • Instead of checking for 200/204 explicitly, I changed to just check for success (200-299). This should prevent returning false for some methods if they change the return status code again.

Let me know if that works.

JohnnyCrazy avatar Oct 12 '24 22:10 JohnnyCrazy

I'm closing this for now as it's solved with the latest version, let me know if you find any bugs with the new logic or spotify's responses.

JohnnyCrazy avatar Oct 12 '24 23:10 JohnnyCrazy