2015-12-09 50 views
1

我已經可以從我的Spotify帳戶獲取上次播放曲目的曲目和藝術家。代碼:使用Last.fm獲取圖像API

$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=xxxxxx&api_key=xxxxxxxxx&limit=2&nowplaying=false&format=json&callback=?", function(data) { 
     var html = ''; 
     var counter = 1; 
     $.each(data.recenttracks.track, function(i, item) { 
      if(counter == 1) { 
      html += '<span>' + item.name + '<br /> ' + item.artist['#text'] + '</span>' + item.image; 
      } 
      counter++ 
     }); 

     $('.listening-to').append(html); 

    }); 

但item.image產生:

undefined 
+0

不要高呼,不要回答! – SFDSF

回答

0

大概專輯圖像不包括在從你正在做(用戶最近的軌道)的API請求的響應。或者如果是這樣,你試圖訪問錯誤的JSON屬性。嘗試重複檢查原始JSON響應以查看專輯圖像URI是否存在。如果不是,則需要單獨調用API才能獲取更詳細的相冊信息。