获取特定用户关注的用户列表 - SoundCloud API
Get a list of users followed by a particular user - SoundCloud API
希望检索特定用户关注的用户列表。不确定我在这里做错了什么,但我们将不胜感激。我在 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);
}
});
看来您需要使用 ID 而不是用户名。
我已经将你的 fiddle 更改为那个,它显示的关注者:
//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
编辑:
我已经更改了fiddle,您只需输入用户名即可。不花哨,但希望它能对你有所帮助:
//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());
});
}
希望检索特定用户关注的用户列表。不确定我在这里做错了什么,但我们将不胜感激。我在 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);
}
});
看来您需要使用 ID 而不是用户名。
我已经将你的 fiddle 更改为那个,它显示的关注者:
//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
编辑:
我已经更改了fiddle,您只需输入用户名即可。不花哨,但希望它能对你有所帮助:
//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());
});
}