I'm using jQuery to display last.fm data on my website. In this case, I'm trying to show my last song on my last.fm profile, using the code below:
$.getJSON('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=joaoramos&api_key=a72cc897d849cfbff9a677871699e3f2&limit=1&format=json&callback=?', function(data) {
track = data.recenttracks.track[0];
var artist = track.artist['#text'],
song = track.name,
url = track.url,
src = track.image[3]['#text'];
if (src == '' || src == null || src == 'undefined') {
var src = 'http://joao.pt/wp-content/themes/joaoramos/img/music.jpg';
}
$('#lastfm a').attr('href', url);
$('#lastfm a').attr('title', 'Last song scrobbed on Last.fm: <em>'+song+'</em> by '+artist);
$('#lastfm a img').attr('alt', song+' by '+artist);
$('#lastfm a img').attr('src', src);
});
I'm probably not using the correct path in the JSON object (some times I get a Uncaught TypeError: Cannot read property 'artist' of undefined
console error, but not always), because most of the times nothing is shown on the third of the three circles on my website (being the first one the last shot on Dribbble, the second the last shot on Flickr, and the last one the last song on last.fm). Any suggestions?