mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #235] Fatal error #167
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#167
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@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.
@ghost commented on GitHub (Sep 30, 2021):
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?
@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...
@jwilsson commented on GitHub (Oct 1, 2021):
Hey!
Could you wrap your call to
$api->me()in atry/catchand 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
SpotifyWebAPIinstance on the fly. Quick and dirty example:And thanks @kasperkamperman, I'll add a note about it to the README.
@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.
@jwilsson commented on GitHub (Oct 2, 2021):
Hey!
Can you try again with this code, hopefully we'll get some more info:
@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" }@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.phpfile in thevendordirectory in your project (should be located atvendor/jwilsson/spotify-web-api-php/src/Request.php) around line 223: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 😅
@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.
@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/
@jwilsson commented on GitHub (Oct 5, 2021):
I've just pushed
5.0.1which 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.
@ghost commented on GitHub (Oct 5, 2021):
For sure, i'll try to do that just now. Should i call the catch exception
I'll give a response soon.
@jwilsson commented on GitHub (Oct 6, 2021):
Printing the exception message should be enough with the latest changes in
5.0.1, for example:@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?
@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?
@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?
@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.
@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).