Play Playlist Or Track By Permalink Not Trackid
I have an embedded player that works by trackId but: I but I am trying to get non-technical users to embed the tracks or playlists into pages. I sometimes need to regenerate the
Solution 1:
See SoundCloud's API docs on resolve
:
The resolve resource allows you to lookup and access API resources when you only know the SoundCloud.com URL.
$ curl -v 'http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/matas/hobnotropic&client_id=YOUR_CLIENT_ID' < HTTP/1.1302 Moved Temporarily < Location: http://api.soundcloud.com/tracks/49931.json
This request will resolve and redirect to the API resource URL for the track http://soundcloud.com/matas/hobnotropic. Just follow the redirect and you will get the representation you want. The resolver supports URLs for:
- users
- tracks
- playlists (sets)
- groups
- apps
You can take a the permalink from a user and get the track or playlist ID like so:
functiongetSoundCloudId(permalink, callback) {
var resolve = 'http://api.soundcloud.com/resolve.json?client_id=YOUR_CLIENT_ID&url=';
var request = newXMLHttpRequest();
request.onreadystatechange = function(){
if (this.readyState === 4 && this.responseText) {
var response = JSON.parse(this.responseText);
if (response.id) callback(response.id);
}
};
request.open('get', resolve+permalink, true);
request.send();
}
Then you use it like so:
getSoundCloudId('https://soundcloud.com/matas/sets/library-project', function(id){
// Do stuff with the IDconsole.log(id);
})
Post a Comment for "Play Playlist Or Track By Permalink Not Trackid"