使用Last.fm API获取图像

Getting image with Last.fm API

本文关键字:获取 图像 API fm Last 使用      更新时间:2023-09-26

我已经可以从我的Spotify帐户中获得上次播放曲目的曲目和艺术家。代码:

    $.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

使用item.image[3]['#text']而不是item.image

您所做的API请求(用户最近的曲目)的响应中可能不包括专辑图像。或者,如果是,则表示您试图访问错误的JSON属性。请尝试仔细检查原始JSON响应,看看相册图像URI是否在其中。如果不是,你将不得不单独调用API来获取更详细的专辑信息。