Search code examples
javascriptcsshtmlspotify

I'm making my portfolio, and I'd like to use the Spotify API to show what I'm currently listening to, but don't want to use the Play button


Mostly self-explanatory, but I just want the song title and artist sent as a JavaScript plain text object, so I can style it myself in CSS. And possibly a way for it to link back to the song on Spotify would be cool too.


Solution

  • Link your spotify to Last FM - http://www.spotify.com/uk/about/spotify-on-the-web/spotify-last-fm/

    Then grab an API Key when you've signed up for Last FM and you can show what you've listened too with the following script (requires jQuery) & html:

    <ul>
    <li class=”artist”>Artist: &nbsp; </li>
    <li class=”track”>Track: &nbsp; </li>
    </ul>  
    
    
    $.getJSON('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=[USERNAME]&api_key=[KEY]&format=json', function(data) {
    
    var artist = $(".artist"),
    track = $(".track"),
    artistVal = data.recenttracks.track[0].artist["#text"],
    trackVal = data.recenttracks.track[0].name;
    
    artist.append(artistVal);
    track.append(trackVal);
    
    });
    

    Replace [Key] with API key and [Username] with your Last FM username