gpt4 book ai didi

javascript - 如何使用 Api 将正在播放的 last.fm 添加到我的网站中

转载 作者:行者123 更新时间:2023-11-28 00:25:16 24 4
gpt4 key购买 nike

大家好,我一直想弄清楚,但我对此很烂,我在谷歌上找到了这段代码,我添加了它并更改了我需要的内容,但仍然不起作用,我真的需要这个用于我的网站:http://www.balkan-party.cf/

我在这里找到代码:http://www.samkitson.co.uk/using-json-to-access-last-fm-recently-played-tracks/

我在js中需要的last.fm用户名:alicajdin ANDAPI key :24f6b03517ad9984de417be5d10e150b

这就是我所做的:

$(document).ready(function() {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=alicajdin&api_key=24f6b03517ad9984de417be5d10e150b&limit=2&format=json&callback=?", function(data) {
var html = ''; // we declare the variable that we'll be using to store our information
var counter = 1; // we declare a counter variable to use with the if statement in order to limit the result to 1
$.each(data.recenttracks.track, function(i, item) {
if(counter == 1) {
html += 'Currently listening to: <span><a href="' + item.url + '" target="_blank">' + item.name + '</a> - ' + item.artist['#text'] + '</span>';
} // close the if statement
counter++ // add 1 to the counter variable each time the each loop runs
}); // close each loop
$('.listening-to h5').append(html); // print the information to the document - here I look for the h5 tag inside the div with a class of 'listening-to' and use the jQuery append method to insert the information we've stored in the html variable inside the h5 tag.
}); // close JSON call
});

我创建了该文件,并尝试添加头部部分、页 footer 分,但它不会显示最近的轨道。是的,我在 google crome 上安装了 scroblr

最佳答案

下面</script>添加以下代码:

<div class="listening-to"></div>

然后删除“h5”

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

所以你的代码是这样的:

<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=YOUR_USERNAME&api_key=YOUR_API_KEY&limit=2&format=json&callback=?", function(data) {
var html = '';
var counter = 1;
$.each(data.recenttracks.track, function(i, item) {
if(counter == 1) {
html += 'Currently listening to: <span><a href="' + item.url + '" target="_blank">' + item.name + '</a> - ' + item.artist['#text'] + '</span>';
}
counter++
});
$('.listening-to').append(html);
});
});
</script>
<div class="listening-to"></div>

希望能帮到你。抱歉,我的英语很差(谷歌翻译)

关于javascript - 如何使用 Api 将正在播放的 last.fm 添加到我的网站中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com