mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-27 07:55:49 +03:00
[GH-ISSUE #202] Non matching results. #139
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#139
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 @Pretmaker on GitHub (Sep 28, 2020).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/202
I have a small discrepancy with the results from this library compared to a manual request, and I can't figure out why there is a difference:
Using the following to test:
O-Zone, Eurobeat - Dragostea Din Tei
https://open.spotify.com/track/1axpof5BrjnXOnN4VWR4dC?si=MkvQufnRQceG6dtJR6a09w
So I build my Query as the following:
Dragostea Din Tei artist:O-Zone, Eurobeat
Array
(
[q] => Dragostea Din Tei artist:O-Zone, Eurobeat
[type] => track
)
(edited the files so I can print out the array information that's inside the Search function (SpotifyWebAPI.php line 1730 added:
Also added:
below the sendRequest GET function so I can see the URL that's requested.
Using the developer portal of Spotify to test the results I've verified that it SHOULD give back results:
curl -X "GET" "https://api.spotify.com/v1/search?q=Dragostea%20Din%20Tei%20artist%3AO-Zone%2C%20Eurobeat&type=track&limit=20&offset=0" -H "Accept: application/json" -H "Content-Type: application/json"
(using https://developer.spotify.com/console/get-search-item/?q=Bob&type=artist&market=&limit=2&offset=20&include_external= to be able to fill the data).
Changed the offset param and the limit param because it isn't an insanely popular song that gets released hundreds of times.
Anyways, I get json results from the developer.spotify.com output, but I don't get any output from this PHP library while the query is basically the same.
I place the query and the token into the restlet client of my browser to test it, and it also gives results.
So I have no clue why the PHP library doesn't give back the results, while the web variant of developer.spotify.com and my browser client restlet tester gives back results.
Extra output from the lastRepsone:
Array
(
[headers] => Array
(
[content-type] => application/json; charset=utf-8
[cache-control] => public, max-age=7200
[x-robots-tag] => noindex, nofollow
[access-control-allow-origin] => *
[access-control-allow-headers] => Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context
[access-control-allow-methods] => GET, POST, OPTIONS, PUT, DELETE, PATCH
[access-control-allow-credentials] => true
[access-control-max-age] => 604800
[content-encoding] => gzip
[content-length] => 207
[strict-transport-security] => max-age=31536000
[x-content-type-options] => nosniff
[date] => Mon, 28 Sep 2020 19:56:59 GMT
[server] => envoy
[via] => HTTP/2 edgeproxy, 1.1 google
[alt-svc] => clear
)
)
(didn't use code tags as they fubar with the echo output). Only difference between requests should be the user, as the Spotify Developer web tester unit uses my own personal account with o-auth and not the client and token authorization.
But I will just say that this behavior is ultra weird, but perhaps someone can point me in the right direction of why this doesn't work as I expect it to work.
@jwilsson commented on GitHub (Sep 29, 2020):
Hi!
That's indeed very strange. I think this might have something to do with different markets/countries and tracks available there. I'm for example located in Sweden and my Spotify account is set to Sweden and I'm getting results when using the library. I also saw that the default market in the Developer Console seems to be US.
What happens if you set market in the Developer Console to the country your Spotify account is set to? And what happens if you use an access token from the Developer Console in your PHP code?
@Pretmaker commented on GitHub (Oct 4, 2020):
Right just tested it a little. Strangely it picks up some songs, but it doesn't pick up others. But this behavior is normal when taking into account the country indeed...
The web-developer code uses the authorization code flow, while my PHP code uses the client code flow. The Client code flow doesn't set the market value.
When I use the auth token that the app uses in the Spotify console I get the same result, until I enter the market, then I get the expected output as compared to when I login with the account.
Perhaps it's wise to add a note that when the Client Authorization code flow is used, that the market is also filled in with the options for searching. So on to finding out how to set it now and hopefully this will fix it. From what I tested with the Spotify Developer console web api thingy this will solve it.
@Pretmaker commented on GitHub (Oct 4, 2020):
Yeah, issue was with the market not being set when using the Client Code authorization flow. Changed the call to include the market and then it works:
(songUnparsed is a split function that splits the input string at the " - " mark to get the artists separated from the songname. This helps in filtering out karaoke hits and stuff.
$api->search($songUnparsed[1]." artist:".$songUnparsed[0], 'track', ['market' => 'gb']);