How to play a private track with soundcloud Javascript SDK

I have a problem with my personal tracks. In my soundcloud account, I have public tracks and private tracks. When the track is public, it is fixed, but when I am a private track, the api returns an error 404: GET http://api.soundcloud.com/tracks/123?client_id=xxxxx&format=json&_status_code_map[302†=200 404 (not found) in my console.

Here is my function to play the track:

// Play a Single track 
$('#app').on('click','.play_btn_single',function(event){
    event.preventDefault();
    var el = $(this);
    var id = el.attr('id');


    SC.stream('/tracks/'+id,function(sound){
        sound.play();
    });


});

Thank you for your help.

+4
source share
2 answers

. - HTML5 ( Jameal G. ) - "" , "embed" iframe .

, , secret_token, - ( ) API, ( , HTTP- Authorization: Oauth 123…).

API . , :

HTML:

<audio controls></audio>

JS, jQuery, :

var clientId = 'client_id=YOUR_CLIENT_ID',
    sekretToken = 'secret_token=s-wwC6c',
    trackUri = 'https://api.soundcloud.com/tracks/128310939.json?' + 
               secretToken + '&' + clientId,
    audio = jQuery('audio');

jQuery
  .get(trackUri)
  .then(function (result) {
    // do not forget to supply client_id also when querying for stream url
    audio.attr('src', result.stream_url + clientId);
  });

http://jsbin.com/yerilu/edit?html,js,output

UPD. .

  • - SoundCloud , -, "" ( " " ). "Private Share" - - .

  • API ( Oauth HTTP-, Authorization: Oauth 123…, , ) , secret_token , .

+2

, , . API SoundCloud:

" , , client_id . stream , ."

. https://developers.soundcloud.com/docs/api/guide#authentication

+2

All Articles