问题
Looking to retrieve a list of users followed by a particular user. Not sure what I'm doing wrong here but any help would be much appreciated. My code in 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:
Lookslike you need to use the id instead of the username.
I have changed your fiddle to that, its displaying the followers:
//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/
You may want to have a look on the resolve endpoint to still use the username as input.
https://developers.soundcloud.com/docs/api/reference#resolve
EDIT:
I have changed the fiddle that you just need to enter the username. not fancy but hope it will help you a bit:
//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/
来源:https://stackoverflow.com/questions/31559484/get-a-list-of-users-followed-by-a-particular-user-soundcloud-api