Search code examples
phpspotifyspotify-app

How can I get number of followers with Spotify API?


I'm trying to get an artist's number of followers.

If I use the metadata api call

http://ws.spotify.com/lookup/1/?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ

I just get the name of the artist.


Solution

  • I'm assuming you want a PHP solution.

    Using the spotify-web-api-php library (shameless self promotion) it's really easy. Take a look at this example:

    <?php
    require_once 'src/Request.php';
    require_once 'src/SpotifyWebAPI.php';
    
    $api = new SpotifyWebAPI\SpotifyWebAPI();
    $artist = $api->getArtist('0OdUWJ0sBjDrqHygGUXeCF');
    
    echo '<b>Number of followers:</b> ' . $artist->followers->total;
    

    As mentioned earlier, also take a look at the official Spotify docs.