jwilsson / spotify-web-api-php

A PHP wrapper for Spotify's Web API.
MIT License
862 stars 156 forks source link

Search Syntax Question #212

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi - firstly, thank you for writing this excellent repository.

I am working on the search part of the API, and this is my sample code:

$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setAccessToken($accessToken);

$options = ['offset' => 0,'limit' => 5,'year' => 2016];
$search = $api->search($str,'album', $options);

If I search for something, e.g. trees, and I check the 'href' attribute value that's returned by the API, it is this:

https://api.spotify.com/v1/search?query=trees&type=album&offset=0&limit=5

It seems that the Year part of the option array is ignored.

Am I doing something wrong? I searched the Closed Issues before raising this new issue.

I also tried setting the Year as a String as follows but get the same result:

$options = ['offset' => 0,'limit' => 5,'year' => '2016'];

Thanks

jwilsson commented 3 years ago

Hi! The "year" filter is passed with the actual query string, for example:

$str = $str . ' year:2016';
$search = $api->search($str,'album', $options);

The Spotify docs has more in-depth info, but don't worry about encoding spaces. The library will handle it for you.

Hope this helps!

ghost commented 3 years ago

Hi Jonathan - that's a big help, thank you very much for your helpful reply, it's much appreciated :-)