获取特定用户后面的用户列表 - SoundCloud API

时间:2015-07-22 09:42:58

标签: javascript soundcloud

希望检索特定用户后跟的用户列表。不知道我在这里做错了什么,但任何帮助将不胜感激。我在jsfiddle中的代码:http://jsfiddle.net/jchan11/3dbvagz5/

var followingsList = [];//array to store users you follow
var USER = "the_chanman";

SC.get("/users/"+USER+"/followings",{limit:10}, function(users){
    for(var i = 0; i < users.length; i++){
        //store users in followsList array
        followingsList.push(users[i].username);
    }
});    

1 个答案:

答案 0 :(得分:0)

看起来你需要使用id而不是用户名。

我已经改变了你的小提琴,它显示了粉丝:

//Initialize soundcloud API with client ID
SC.initialize({
    client_id: "887b335a80f3e625454ebca548c53d96"
});
var followingsList = [];
var likesList = [];

$(document).ready(function () {
    var USER = "the_chanman";
    var id = 83114659;
    $("#user").html(USER);

    SC.get("/users/"+id+"/followings",{limit:10}, function(users){
        for(var i = 0; i < users.length; i++){
            //store users in followsList array
            followingsList.push(users[i].username);
        }
        $("#followings").html(followingsList.toString());
    });    

    SC.get("/users/"+id+"/favorites", {limit: 10}, function(tracks){
         for (var i = 0; i < tracks.length; i++) {
            // store tracks in likesList array
            likesList.push(tracks[i].title);
          }
        $("#likes").html(likesList.toString());
    });
});

http://jsfiddle.net/iambnz/gp9gbfba/

您可能希望查看解析端点以仍然使用用户名作为输入。

https://developers.soundcloud.com/docs/api/reference#resolve

编辑:

我已经改变了你只需要输入用户名的小提琴。不花哨但希望它会对你有所帮助:

//Initialize soundcloud API with client ID
SC.initialize({
    client_id: "887b335a80f3e625454ebca548c53d96"
});
var followingsList = [];
var likesList = [];

var scdisplayname = 'bnzlovesyou';
var scurl = 'https://soundcloud.com/' + scdisplayname;   

$(document).ready(function () {
SC.get('/resolve', { url: scurl }, function(result) {  
    if(result.kind == 'user')
    {id = result.id;
     $("#user").html(result.permalink);
     getUserData(id);
    }
    else {
    alert('no valid username');
    }    
});
}); 

function getUserData(userid){    
SC.get("/users/"+id+"/followings",{limit:10}, function(users){
   for(var i = 0; i < users.length; i++){
   //store users in followsList array
   followingsList.push(users[i].username);
   }
$("#followings").html(followingsList.toString());
});    

SC.get("/users/"+id+"/favorites", {limit: 10}, function(tracks){
   for (var i = 0; i < tracks.length; i++) {
   // store tracks in likesList array
   likesList.push(tracks[i].title);
   }
$("#likes").html(likesList.toString());
});
}    

http://jsfiddle.net/iambnz/vvp6vnbm/