spotify-dart icon indicating copy to clipboard operation
spotify-dart copied to clipboard

startOrResume throws error code 400 (malformed json)

Open adamkoch opened this issue 1 year ago • 4 comments

When I call startOrResume() I am getting error 400:

flutter: Error Code: 400
Malformed json
flutter: 
#0      SpotifyApiBase.handleErrors (package:spotify/src/spotify_base.dart:238:7)
#1      SpotifyApiBase._requestWrapper (package:spotify/src/spotify_base.dart:212:16)
<asynchronous suspension>
#2      SpotifyApiBase._putImpl (package:spotify/src/spotify_base.dart:201:12)
<asynchronous suspension>
#3      PlayerEndpoint.startOrResume (package:spotify/src/endpoints/player.dart:97:5)
<asynchronous suspension>
#4      _SpotifyScreenState._buildSpotifyConnected.<anonymous closure> (package:my_app/screens/spotify.dart:192:23)
<asynchronous suspension>

Is there a way to turn on debug logging so I can see the actual http requests being sent out and see what the issue is with the request?

Additional info:

  • Flutter 3.16.1
  • Testing on iOS
  • Other playback controls work fine (prev/next track, stop playback and everything else I have tried)
  • I am using the PKCE flow (https://github.com/rinukkusu/spotify-dart/issues/81) - but I also tested with secret and it still doesn't seem to work
  • Tested using v0.12.0 as well as master from github

adamkoch avatar Dec 01 '23 05:12 adamkoch

I used Flutter DevTools to inspect the network requests and it appears all fine. It's sending a simple PUT request to: https://api.spotify.com/v1/me/player/play?

Comparing to the sample request in the Spotify docs it looks the same AFAICT. I kept the request body empty for both of them.

adamkoch avatar Dec 01 '23 05:12 adamkoch

@adamkoch So far there are no debug tools in this library. However, this is a good idea. I'll create another issue for this.

hayribakici avatar Dec 01 '23 11:12 hayribakici

To follow up, I found the issue was that: .player.startOrResume()

Adds an empty request body of "". Which Spotify considers a malformed request which is why it's not working. I looked over the code but couldn't find where to have it return an empty body when there are no parameters supplied. If you have any code pointers please let me know.

adamkoch avatar Dec 11 '23 03:12 adamkoch

Perhaps here, default is to set body to empty string vs null: https://github.com/rinukkusu/spotify-dart/blob/v0.11.0/lib/src/spotify_base.dart#L167

adamkoch avatar Dec 11 '23 03:12 adamkoch

Fix is released with v0.13.4!

rinukkusu avatar Mar 23 '24 17:03 rinukkusu