Soundcloud Api , Please Help


#1

Hello,

Just to make it easier i have this working script on jsfiddle : https://jsfiddle.net/33wbzhpk/

Right now it works but its the same track id everytime you open that page.

**I need some help to make this script generate a new track id on page refresh **
Is this possible and how please?


#2

This post was flagged by the community and is temporarily hidden.


#3

The solution is quite easy.

We have to:

  1. Get all the tracks (we have to delete limit)
  2. Pick random track

SC.initialize({
    client_id: "9d7b8f85e4719525a2ca97e8814e14fe",
    redirect_uri: "",
});

var userId = 165459296; //this is the user id to loop tracks

SC.get("/tracks", {
    user_id: userId,
}, function(tracks) {
    var randomTrack = tracks[Math.floor(Math.random() * tracks.length)];
    $("<div/>").html(randomTrack.id).appendTo("#track-list");
});

#4

Thank you so much this worked.


#5

You're very welcome :slight_smile: