[GH-ISSUE #224] Malformed JSON error when using play #158

Closed
opened 2026-02-27 19:26:22 +03:00 by kerem · 6 comments
Owner

Originally created by @ericlove02 on GitHub (Mar 2, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/224

I am getting this error when I try and use the Play endpoint:
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Malformed json in D:\wamp64\www\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 57

My code:
`<?php
require '../vendor/autoload.php';

$api = new SpotifyWebAPI\SpotifyWebAPI();
session_start();

$api->setAccessToken($_SESSION['token']);
$api->play($_SESSION['playback_device']);`

I am using the same code (with the endpoint change of course) for pause, next, and previous and am having no problems. Any ideas?

Originally created by @ericlove02 on GitHub (Mar 2, 2021). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/224 I am getting this error when I try and use the Play endpoint: Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Malformed json in D:\wamp64\www\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 57 My code: `<?php require '../vendor/autoload.php'; $api = new SpotifyWebAPI\SpotifyWebAPI(); session_start(); $api->setAccessToken($_SESSION['token']); $api->play($_SESSION['playback_device']);` I am using the same code (with the endpoint change of course) for pause, next, and previous and am having no problems. Any ideas?
kerem 2026-02-27 19:26:22 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jwilsson commented on GitHub (Mar 2, 2021):

Hey!
Spotify no longer seems to like an empty $options being sent. Passing null seems to be a workaround until I can get a fix out. For example:

$api->play($_SESSION['playback_device'], null);

Hope that solves it for you!

<!-- gh-comment-id:788609520 --> @jwilsson commented on GitHub (Mar 2, 2021): Hey! Spotify no longer seems to like an empty `$options` being sent. Passing `null` seems to be a workaround until I can get a fix out. For example: ```php $api->play($_SESSION['playback_device'], null); ``` Hope that solves it for you!
Author
Owner

@ericlove02 commented on GitHub (Mar 2, 2021):

Thanks for the idea. I tried that and now I am getting a new error:
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Server error. in D:\wamp64\www\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 57

<!-- gh-comment-id:788642269 --> @ericlove02 commented on GitHub (Mar 2, 2021): Thanks for the idea. I tried that and now I am getting a new error: Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Server error. in D:\wamp64\www\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 57
Author
Owner

@ericlove02 commented on GitHub (Mar 2, 2021):

It works correctly when I pass a uri, for example:
$api->play($_SESSION['playback_device'], ['uris'=>['spotify:track:5QO79kh1waicV47BqGRL3g']]);
but it does not like:
$api->play($_SESSION['playback_device'], null);

<!-- gh-comment-id:788644310 --> @ericlove02 commented on GitHub (Mar 2, 2021): It works correctly when I pass a uri, for example: $api->play($_SESSION['playback_device'], ['uris'=>['spotify:track:5QO79kh1waicV47BqGRL3g']]); but it does not like: $api->play($_SESSION['playback_device'], null);
Author
Owner

@jwilsson commented on GitHub (Mar 2, 2021):

Hmm, I can't think of anything more right now (unless you're fine with always passing a URI). I'll try and get a fix out ASAP.

<!-- gh-comment-id:788866623 --> @jwilsson commented on GitHub (Mar 2, 2021): Hmm, I can't think of anything more right now (unless you're fine with always passing a URI). I'll try and get a fix out ASAP.
Author
Owner

@ericlove02 commented on GitHub (Mar 2, 2021):

Yeah, I couldn't get it working without passing a uri, so for my application I ended up doing this:

$trackUri = "spotify:track:" . $_GET['id'];
$position = $_GET['pos'];
$api->play($_SESSION['playback_device'], ['uris'=>[$trackUri], 'position_ms'=>$position]);

<!-- gh-comment-id:789102364 --> @ericlove02 commented on GitHub (Mar 2, 2021): Yeah, I couldn't get it working without passing a uri, so for my application I ended up doing this: $trackUri = "spotify:track:" . $_GET['id']; $position = $_GET['pos']; $api->play($_SESSION['playback_device'], ['uris'=>[$trackUri], 'position_ms'=>$position]);
Author
Owner

@jwilsson commented on GitHub (Mar 2, 2021):

I just published 4.2.2 which should solve the issue.

Let me know if it doesn't!

<!-- gh-comment-id:789112739 --> @jwilsson commented on GitHub (Mar 2, 2021): I just published `4.2.2` which should solve the issue. Let me know if it doesn't!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#158
No description provided.