[GH-ISSUE #235] Fatal error #167

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

Originally created by @ghost on GitHub (Sep 30, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/235

Hello,
im trying to use the spotify api, worked really good, but now i'm having some issues which i'm not being able to fix

/vendor/jwilsson/spotify-web-api-php/src/Request.php(239): SpotifyWebAPI\Request->handleResponseError(Object(stdClass), 403)
#1 /home/akaggdvp/public_html/test-flc/api/vendor/jwilsson/spotify-web-api-php/src/Request.php(129): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', '', Array)
/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api('GET', '/v1/me', Array, Array)
/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(1556): SpotifyWebAPI\SpotifyWebAPI->sendRequest('GET', '/v1/me')
vendor/index.php(16): SpotifyWebAPI\SpotifyWebAPI->me(Object(SpotifyWebAPI\Session))
#5 {main}
thrown in /vendor/jwilsson/spotify-web-api-php/src/Request.php on line 59

removed the /home/ dir, etc.

I'm not sure if the "array" means that the client id and secret aren't getting read, but, if there's any possible fix, let me know.

Originally created by @ghost on GitHub (Sep 30, 2021). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/235 Hello, im trying to use the spotify api, worked really good, but now i'm having some issues which i'm not being able to fix /vendor/jwilsson/spotify-web-api-php/src/Request.php(239): SpotifyWebAPI\Request->handleResponseError(Object(stdClass), 403) #1 /home/akaggdvp/public_html/test-flc/api/vendor/jwilsson/spotify-web-api-php/src/Request.php(129): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', '', Array) /vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api('GET', '/v1/me', Array, Array) /vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(1556): SpotifyWebAPI\SpotifyWebAPI->sendRequest('GET', '/v1/me') vendor/index.php(16): SpotifyWebAPI\SpotifyWebAPI->me(Object(SpotifyWebAPI\Session)) #5 {main} thrown in /vendor/jwilsson/spotify-web-api-php/src/Request.php on line 59 removed the /home/ dir, etc. I'm not sure if the "array" means that the client id and secret aren't getting read, but, if there's any possible fix, let me know.
kerem 2026-02-27 19:26:24 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@kasperkamperman commented on GitHub (Sep 30, 2021):

I just ran in the same issue. You need to add the username of the account you want to give access to the API. This is a recent change and not documented in the readme.
So next to edit settings, also set the users you'd like to give access.

<!-- gh-comment-id:931717403 --> @kasperkamperman commented on GitHub (Sep 30, 2021): I just ran in the same issue. You need to add the username of the account you want to give access to the API. This is a recent change and not documented in the readme. So next to edit settings, also set the users you'd like to give access.
Author
Owner

@ghost commented on GitHub (Sep 30, 2021):

I just ran in the same issue. You need to add the username of the account you want to give access to the API. This is a recent change and not documented in the readme. So next to edit settings, also set the users you'd like to give access.

Alright, thanks.

Also, is it possible to manage multiple users playlist via $api->addPlaylistTracks?

so for example, i have 2 access_tokens on my database, and i want to insert multiple tracks to both of those account at the same time, how is that possible?

<!-- gh-comment-id:931726541 --> @ghost commented on GitHub (Sep 30, 2021): > I just ran in the same issue. You need to add the username of the account you want to give access to the API. This is a recent change and not documented in the readme. So next to edit settings, also set the users you'd like to give access. Alright, thanks. Also, is it possible to manage multiple users playlist via $api->addPlaylistTracks? so for example, i have 2 access_tokens on my database, and i want to insert multiple tracks to both of those account at the same time, how is that possible?
Author
Owner

@ghost commented on GitHub (Oct 1, 2021):

I'm still getting the same error even after adding the account on dashboard at users and access

the

SpotifyWebAPI\Request->send('GET', 'https://api.spo...', '', Array)
SpotifyWebAPI\Request->api('GET', '/v1/me', Array, Array)

no idea what this is, this works, then after a while just doesn't. Idk what this is...

<!-- gh-comment-id:931803979 --> @ghost commented on GitHub (Oct 1, 2021): I'm still getting the same error even after adding the account on dashboard at users and access the SpotifyWebAPI\Request->send('GET', 'https://api.spo...', '', Array) SpotifyWebAPI\Request->api('GET', '/v1/me', Array, Array) no idea what this is, this works, then after a while just doesn't. Idk what this is...
Author
Owner

@jwilsson commented on GitHub (Oct 1, 2021):

Hey!
Could you wrap your call to $api->me() in a try/catch and print the exception so we get the exact error?

Regarding your other question, there shouldn't be any problems keeping multiple access tokens in a database and then changing the access tokens on a SpotifyWebAPI instance on the fly. Quick and dirty example:

$accessTokens = [...]; // Fetched from your database

foreach ($accessTokens as $accessToken) {
  $api->setAccessToken($accessToken);

  $api->addPlaylistTracks(...);
}

And thanks @kasperkamperman, I'll add a note about it to the README.

<!-- gh-comment-id:931893365 --> @jwilsson commented on GitHub (Oct 1, 2021): Hey! Could you wrap your call to `$api->me()` in a `try/catch` and print the exception so we get the exact error? Regarding your other question, there shouldn't be any problems keeping multiple access tokens in a database and then changing the access tokens on a `SpotifyWebAPI` instance on the fly. Quick and dirty example: ```php $accessTokens = [...]; // Fetched from your database foreach ($accessTokens as $accessToken) { $api->setAccessToken($accessToken); $api->addPlaylistTracks(...); } ``` And thanks @kasperkamperman, I'll add a note about it to the README.
Author
Owner

@ghost commented on GitHub (Oct 1, 2021):

Hello! I've tried using the Try { } then:

catch (Exception $e) {
$ex = $e->getMessage();
die('Caught exception: '.$ex.'');
}

the reponse i'm getting is "An unknown error occurred."

What do you think the error might be?

Thanks.

<!-- gh-comment-id:932541235 --> @ghost commented on GitHub (Oct 1, 2021): Hello! I've tried using the Try { } then: catch (Exception $e) { $ex = $e->getMessage(); die('Caught exception: '.$ex.''); } the reponse i'm getting is "An unknown error occurred." What do you think the error might be? Thanks.
Author
Owner

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

Hey!
Can you try again with this code, hopefully we'll get some more info:

try {
  // Anything else you might have...

  $api->me();
} catch (Exception $e) {
   $lastResponse = $api->getRequest()->getLastResponse();

  var_dump($lastResponse);
}
<!-- gh-comment-id:932702903 --> @jwilsson commented on GitHub (Oct 2, 2021): Hey! Can you try again with this code, hopefully we'll get some more info: ```php try { // Anything else you might have... $api->me(); } catch (Exception $e) { $lastResponse = $api->getRequest()->getLastResponse(); var_dump($lastResponse); } ```
Author
Owner

@ghost commented on GitHub (Oct 2, 2021):

There's a really long message from the last response:

array(4) { ["body"]=> NULL ["headers"]=> array(14) { ["cache-control"]=> string(18) "private, max-age=0" ["access-control-allow-origin"]=> string(1) "*" ["access-control-allow-headers"]=> string(150) "Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token" ["access-control-allow-methods"]=> string(38) "GET, POST, OPTIONS, PUT, DELETE, PATCH" ["access-control-allow-credentials"]=> string(4) "true" ["access-control-max-age"]=> string(6) "604800" ["content-encoding"]=> string(4) "gzip" ["content-length"]=> string(2) "71" ["strict-transport-security"]=> string(16) "max-age=31536000" ["x-content-type-options"]=> string(7) "nosniff" ["date"]=> string(29) "Sat, 02 Oct 2021 15:03:04 GMT" ["server"]=> string(5) "envoy" ["via"]=> string(28) "HTTP/2 edgeproxy, 1.1 google" ["alt-svc"]=> string(5) "clear" } ["status"]=> int(403) ["url"]=> string(29) "https://api.spotify.com/v1/me" }

<!-- gh-comment-id:932766878 --> @ghost commented on GitHub (Oct 2, 2021): There's a really long message from the last response: `array(4) { ["body"]=> NULL ["headers"]=> array(14) { ["cache-control"]=> string(18) "private, max-age=0" ["access-control-allow-origin"]=> string(1) "*" ["access-control-allow-headers"]=> string(150) "Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token" ["access-control-allow-methods"]=> string(38) "GET, POST, OPTIONS, PUT, DELETE, PATCH" ["access-control-allow-credentials"]=> string(4) "true" ["access-control-max-age"]=> string(6) "604800" ["content-encoding"]=> string(4) "gzip" ["content-length"]=> string(2) "71" ["strict-transport-security"]=> string(16) "max-age=31536000" ["x-content-type-options"]=> string(7) "nosniff" ["date"]=> string(29) "Sat, 02 Oct 2021 15:03:04 GMT" ["server"]=> string(5) "envoy" ["via"]=> string(28) "HTTP/2 edgeproxy, 1.1 google" ["alt-svc"]=> string(5) "clear" } ["status"]=> int(403) ["url"]=> string(29) "https://api.spotify.com/v1/me" }`
Author
Owner

@jwilsson commented on GitHub (Oct 4, 2021):

Hmm, I did some further digging with a new Spotify app and a user that wasn't added to that app and I got the exact same error. But once I added the user to the app it started working (it took a few minutes and might require a relog).

So I just wanted as you to double check your app settings as mentioned above so see that the user is in fact added to the app.

If you're still getting errors could you add the following line to the Request.php file in the vendor directory in your project (should be located at vendor/jwilsson/spotify-web-api-php/src/Request.php) around line 223:

[$headers, $body] = $this->splitResponse($response);
var_dump($body); // Add this line
$body = json_decode($body, $this->options['return_assoc']);

And see if we're getting an even better error. I'll also look into making this process easier with a proper way to do it without having to hack the library code yourself 😅

<!-- gh-comment-id:933140580 --> @jwilsson commented on GitHub (Oct 4, 2021): Hmm, I did some further digging with a new Spotify app and a user that wasn't added to that app and I got the exact same error. But once I added the user to the app it started working (it took a few minutes and might require a relog). So I just wanted as you to double check your app settings as mentioned above so see that the user is in fact added to the app. If you're still getting errors could you add the following line to the `Request.php` file in the `vendor` directory in your project (should be located at `vendor/jwilsson/spotify-web-api-php/src/Request.php`) around line 223: ```php [$headers, $body] = $this->splitResponse($response); var_dump($body); // Add this line $body = json_decode($body, $this->options['return_assoc']); ``` And see if we're getting an even better error. I'll also look into making this process easier with a proper way to do it without having to hack the library code yourself 😅
Author
Owner

@ghost commented on GitHub (Oct 4, 2021):

For sure. How exactly do you mean to add the user to the app manually? as i want the application to be fully automated. By user are your refering to the API account or the logining one from the site?

And i'll try to do that and give you a response soon.

<!-- gh-comment-id:933842837 --> @ghost commented on GitHub (Oct 4, 2021): For sure. How exactly do you mean to add the user to the app manually? as i want the application to be fully automated. By user are your refering to the API account or the logining one from the site? And i'll try to do that and give you a response soon.
Author
Owner

@jwilsson commented on GitHub (Oct 5, 2021):

Yeah, while your app is in Development Mode I'm afraid you'll need to add users to your app manually (by using the email they used to sign up for Spotify with), but when you're feeling ready to publish it you can request Extended Quota Mode from Spotify which will allow users to be added automatically.

Spotify has some more info around it: https://developer.spotify.com/community/news/2021/05/27/improving-the-developer-and-user-experience-for-third-party-apps/

<!-- gh-comment-id:934053144 --> @jwilsson commented on GitHub (Oct 5, 2021): Yeah, while your app is in Development Mode I'm afraid you'll need to add users to your app manually (by using the email they used to sign up for Spotify with), but when you're feeling ready to publish it you can request Extended Quota Mode from Spotify which will allow users to be added automatically. Spotify has some more info around it: https://developer.spotify.com/community/news/2021/05/27/improving-the-developer-and-user-experience-for-third-party-apps/
Author
Owner

@jwilsson commented on GitHub (Oct 5, 2021):

I've just pushed 5.0.1 which should give you a better exception message without having to hack the library files. Could you run it again wrapping the $api->me() call in a try/catch and printing the error?

In my case Spotify replied with "User not registered in the Developer Dashboard" which went away as soon as I added the user to the app.

<!-- gh-comment-id:934667520 --> @jwilsson commented on GitHub (Oct 5, 2021): I've just pushed `5.0.1` which should give you a better exception message without having to hack the library files. Could you run it again wrapping the `$api->me()` call in a try/catch and printing the error? In my case Spotify replied with "User not registered in the Developer Dashboard" which went away as soon as I added the user to the app.
Author
Owner

@ghost commented on GitHub (Oct 5, 2021):

For sure, i'll try to do that just now. Should i call the catch exception

$lastResponse = $api->getRequest()->getLastResponse();

  var_dump($lastResponse);

I'll give a response soon.

<!-- gh-comment-id:934977363 --> @ghost commented on GitHub (Oct 5, 2021): For sure, i'll try to do that just now. Should i call the catch exception ``` $lastResponse = $api->getRequest()->getLastResponse(); var_dump($lastResponse); ```` I'll give a response soon.
Author
Owner

@jwilsson commented on GitHub (Oct 6, 2021):

Printing the exception message should be enough with the latest changes in 5.0.1, for example:

try {
  $api->me();
} catch (Exception $e) {
  echo $e->getMessage();

  // Or var_dump($e);
}
<!-- gh-comment-id:935402515 --> @jwilsson commented on GitHub (Oct 6, 2021): Printing the exception message should be enough with the latest changes in `5.0.1`, for example: ```php try { $api->me(); } catch (Exception $e) { echo $e->getMessage(); // Or var_dump($e); }
Author
Owner

@ghost commented on GitHub (Oct 6, 2021):

It says "User not registered in the Developer Dashboard". Now i understand the error. Thanks a LOT for hacking the files haha! So, i have 2 more questions. In order for the user to be automatically added i need to request the "extended quote" and how can i login more than 2 accounts on spotify? how can i unset the session in order to login multiple accounts at once on spotify from the same user?

<!-- gh-comment-id:936954151 --> @ghost commented on GitHub (Oct 6, 2021): It says "User not registered in the Developer Dashboard". Now i understand the error. Thanks a LOT for hacking the files haha! So, i have 2 more questions. In order for the user to be automatically added i need to request the "extended quote" and how can i login more than 2 accounts on spotify? how can i unset the session in order to login multiple accounts at once on spotify from the same user?
Author
Owner

@kasperkamperman commented on GitHub (Oct 6, 2021):

Indeed in order to automatically add, you need extended quote (or probably apply to some rules) or add user e-mails manually.
Why do you need to login in multiple accounts at the same time?

<!-- gh-comment-id:936995433 --> @kasperkamperman commented on GitHub (Oct 6, 2021): Indeed in order to automatically add, you need extended quote (or probably apply to some rules) or add user e-mails manually. Why do you need to login in multiple accounts at the same time?
Author
Owner

@ghost commented on GitHub (Oct 6, 2021):

I'm working on a project "playlist controller" where you can basically control your playlist from a site. Prespectively, you can insert a track into multiple Playlists and not do that manually.

Also, how can i list only PRIVATE or OWNED playlists? and not all of them?

<!-- gh-comment-id:937190090 --> @ghost commented on GitHub (Oct 6, 2021): I'm working on a project "playlist controller" where you can basically control your playlist from a site. Prespectively, you can insert a track into multiple Playlists and not do that manually. Also, how can i list only PRIVATE or OWNED playlists? and not all of them?
Author
Owner

@jwilsson commented on GitHub (Oct 7, 2021):

Glad we made some progress!

I'm not sure I follow though, you want to add a track to playlists belonging to different users? You would somehow need to get access tokens for each user and store them somewhere. Then it shouldn't be any problems fetching all access tokens, iterating over them, telling the API wrapper about each access token, and then adding the track to each playlist. The code I posted above should give you some pointers.

But I don't think there's a way to list only private or owned playlists other than first calling SpotifyWebAPI::getUserPlaylists and/or SpotifyWebAPI::getMyPlaylists and then filtering the results yourself.

<!-- gh-comment-id:937438871 --> @jwilsson commented on GitHub (Oct 7, 2021): Glad we made some progress! I'm not sure I follow though, you want to add a track to playlists belonging to different users? You would somehow need to get access tokens for each user and store them somewhere. Then it shouldn't be any problems fetching all access tokens, iterating over them, telling the API wrapper about each access token, and then adding the track to each playlist. The code I posted above should give you some pointers. But I don't think there's a way to list only private or owned playlists other than first calling [SpotifyWebAPI::getUserPlaylists](https://github.com/jwilsson/spotify-web-api-php/blob/main/docs/method-reference/SpotifyWebAPI.md#getuserplaylists) and/or [SpotifyWebAPI::getMyPlaylists](https://github.com/jwilsson/spotify-web-api-php/blob/main/docs/method-reference/SpotifyWebAPI.md#getmyplaylists) and then filtering the results yourself.
Author
Owner

@kasperkamperman commented on GitHub (Oct 7, 2021):

Indeed storing accessToken and refreshTokens (make sure you encrypt them) is the way. I made service were multiple playlist of users are updated.

Also, how can i list only PRIVATE or OWNED playlists? and not all of them?
The Spotify API doesn't let you pass a lot of parameters (only offset, limit and fields you'd like to get in the return). So you have to do that filtering in your backend. I mostly include only the fields needed, so filtering get's easier (and the API doesn't have to send data not needed).

<!-- gh-comment-id:937539020 --> @kasperkamperman commented on GitHub (Oct 7, 2021): Indeed storing accessToken and refreshTokens (make sure you encrypt them) is the way. I made service were multiple playlist of users are updated. _Also, how can i list only PRIVATE or OWNED playlists? and not all of them?_ The Spotify API doesn't let you pass a lot of parameters (only offset, limit and fields you'd like to get in the return). So you have to do that filtering in your backend. I mostly include only the fields needed, so filtering get's easier (and the API doesn't have to send data not needed).
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#167
No description provided.