Soundcloud: How do I know the sound cloud track ID right away after uploading a track?
Asked Answered
P

4

5

http://developers.soundcloud.com/docs/api

When I look at the API docs, I see

 SC.stream("/tracks/293", function(sound){
      sound.play();
 });

When I look at the track I uploaded, it only provides me the permalink. How do I get the track ID from the website? Do I always have to do a /resolve to get the ID?

Pyrrhonism answered 20/9, 2013 at 19:46 Comment(0)
V
11

This is probably more manual steps than /resolve, but it is "from the website." The sound id also appears in the embed code when you go to the sound and click "Share".

For example, if you go to a sound page, e.g.:

https://soundcloud.com/lowcountrykingdom/another-ordinary-day

Then click "Share", which brings up a pop up. Click "Embed" to switch to the embed tab, and copy the Embed code, which will look something like:

<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/47580057&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=true"></iframe>

Note the ID in the value of the url query parameter:

url=https%3A//api.soundcloud.com/tracks/47580057
Valparaiso answered 14/12, 2013 at 7:30 Comment(3)
This no longer seems to work. I just see the plain text version of the name in the share link now.Undernourished
How to get this programmatically ?Fighter
If you are using the client side SC library, it looks like the ID's are now provided, whereas they did not use to beCessionary
C
3

I'd use jquery ajax call to grab the data from Soundcloud. Say you save your variables permalink_url and client_id:

$.get('http://api.soundcloud.com/resolve.json?url='+
    permalink_url+'/tracks&client_id='+client_id , function (result) {
        console.log(result);
    });

This should log an array of the songs. Check out this bin for reference http://jsbin.com/viviza/4/edit

Update: This answer is pretty old.

Soundclick docs https://developers.soundcloud.com/docs/api#uploading

The SC object now allows for getting the id's directly

SC.connect().then(function(){
    return SC.get('/me/tracks');
}).then(function(tracks){
    return tracks.map(function(track){
       console.log("you can log the id here too: " + track.id")
       return track.id
    })
})
Cessionary answered 5/4, 2014 at 22:45 Comment(0)
M
1

You could also get all the tracks from a given user id. Then use $.map() to place each of the tracks into an array. Call SC.stream() with song[i].id to play a random song from the array from the array of tracks.

SC.get('/users/123456/tracks/', function(tracks) {

  // get an array of tracks
  var song = $.map(tracks, function(i){
    return i;
  });

  var i = Math.floor(Math.random() * song.length)  // get a random value between 0 & the  of songs in SC account -1


  SC.stream(song[i].id, function(sound){
    sound.play();
  });
});
Merrifield answered 2/3, 2014 at 1:26 Comment(0)
U
1

Using JavaScript to find the track data from a soundcloud song url:

let trackUrl = 'https://soundcloud.com/user-869590724/talk-to-animals-sentra-remix'
let client_id = '<your-client-id>'

let resolveUrl = `http://api.soundcloud.com/resolve.json?url=${trackUrl}/tracks&client_id=${client_id}`
fetch(resolveUrl, {
  method: 'get'
}).then((response) => {
  return response.json()
}).then((result) => {
  /* now you have the track */
  console.log(result)
})
Uniflorous answered 31/1, 2017 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.