获取已在SoundCloud上收藏的曲目的相应播放列表

时间:2015-05-20 04:32:24

标签: api soundcloud

我正在尝试建立一个网站,其中包括从我的soundcloud页面中提取收藏夹。由于SoundCloud的可怕流派标签,我创建了播放列表,我想在我的网站上使用流派标签。我目前有以下代码加载我最近最喜欢的200个网址(为安全起见,代码不包括SC.initialize)

我想将每首歌曲添加到的播放列表拉为网址旁边的文字。

任何帮助将不胜感激!



  var userId = 68219117; // user_id of BeetsnBass

  SC.get("/users/68219117/favorites", {
      user_id: userId,
      limit: 200
  }, function (tracks) {

      var tmp = '';

      for (var i = 0; i < tracks.length; i++) {

          tmp = tracks[i].permalink_url;

          $("<table/>").html(tmp).appendTo("#track-list");
      }
      
      var **playlist** = '';

      for (var i = 0; i < tracks.length; i++) {

          **playlist** = tracks[i].**playlist**;

          $("<table/>").html(**playlist**).appendTo("#genre");
      }

  });
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="//connect.soundcloud.com/sdk.js"></script>
<table>
    <tr>
        <td id="track-list"><td/>
            <td id="genre"><td/>
                <tr/>
                <table/>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

这应该有效:

var userid = 68219117;
var limit = 200;

SC.get("/users/"+userid+"/favorites", {limit: limit}, function (tracks) {
      for (var i = 0; i < tracks.length; i++) {
          getTrackPlaylists(tracks[i].id, tracks[i].permalink_url);    
        }  
});

function getTrackPlaylists(trackid, url){
SC.get("/tracks/" + trackid + "/playlists", function (playlists) {
      for (var i = 0; i < playlists.length; i++) {
          genre = '';
    if(playlists[i].user.id == 68219117){
     console.log(playlists[i].title);   
    genre = playlists[i].title;
   $("<table/>").html(url).appendTo("#track-list");
   $("<table/>").html(genre).appendTo("#genre");
    }
      }    
});
}

http://jsfiddle.net/iambnz/hh9b71px/6/

您可能需要添加一些后备和错误处理,分页..