I'm making a website for a friend who's a DJ. He posts his music on Soundcloud. I am trying to get his music via the Soundcloud api on his website. The problem is, I don't know how to get or select a user with the soundcloud api. With the code I have I can search music by query or genre, but not by user.
function play(){
SC.initialize({
client_id: 'His client, not het user_id'
});
SC.get('/tracks', { q: music},
function(tracks) {
var random = Math.floor(Math.random() * 15);
var track_url = tracks[random].permalink_url;
SC.oEmbed(track_url, {auto_play: true, color: "ff0066"},
document.getElementById("target"));
}
);
}`
You can search for a specific users tracks using the /users/:user_id/tracks
endpoint. For example, for a user with the user_id 293
, you can retrieve their tracks with the following code example:
SC.initialize({
client_id: 'CLIENT_ID'
});
SC.get('/users/293/tracks', function(tracks) {
...
});
If you don't know their user_id
, but have their permalink url, you can use the /resolve
endpoint to retrieve it:
SC.initialize({
client_id: 'CLIENT_ID'
});
SC.get('/resolve', {
url: 'https://soundcloud.com/paulosman'
}, function(user) {
console.log(user.id);
});
Hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.