【问题标题】:Getting image with Last.fm API使用 Last.fm API 获取图像
【发布时间】:2018-10-11 03:49:34
【问题描述】:

我已经可以从我的 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

【问题讨论】:

  • 不要投票也不要回答!

标签: javascript api last.fm


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    专辑图片可能未包含在您发出的 API 请求的响应中(用户最近的曲目)。或者,如果是,您正在尝试访问错误的 JSON 属性。尝试仔细检查原始 JSON 响应以查看专辑图像 URI 是否在其中。如果不是,您将不得不单独调用 API 以获取更详细的专辑信息。

    【讨论】:

      猜你喜欢
      • 2015-11-14
      • 1970-01-01
      • 2018-10-09
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 2013-05-24
      相关资源
      最近更新 更多