Search code examples
phpspotifylibspotify

Limit spotify search results


I am using spotify api to get informations of song but I want to limit search results.

Search results show 20 results as default but I want to do it 1 . Here is my code:

require "SpotifyWebAPIException.php";
require "Request.php";
require "Session.php";
require "SpotifyWebAPI.php";
$session = new SpotifyWebAPI\Session(
    '*******',
    '*******'
);
$api = new SpotifyWebAPI\SpotifyWebAPI();
$session->requestCredentialsToken();
$accessToken = $session->getAccessToken();
$api->setAccessToken($accessToken);
$search = $api->search("Song Name", ["track"]);

I looked at official documents but I couldn't found how to do it.


Solution

  • Assuming you are using this client, then you are looking for this:

    $search = $api->search("Song Name", ["track"], ["limit" => 1]);