Soundcloud:上传曲目后,如何立即知道声音云轨道ID?

时间:2013-09-20 19:46:50

标签: soundcloud

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

当我查看API文档时,我看到了

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

当我查看我上传的曲目时,它只为我提供了永久链接。如何从网站上获取曲目ID?我是否总是必须做/决定获取ID?

4 个答案:

答案 0 :(得分:10)

这可能是比/解决更多的手动步骤,但它来自网站。"当您转到声音并单击"分享"时,声音ID也会出现在嵌入代码中。

例如,如果您转到声音页面,例如:

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

然后点击"分享",这会弹出一个弹出窗口。点击"嵌入"切换到嵌入选项卡,并复制嵌入代码,如下所示:

<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>

请注意url查询参数值中的ID:

url=https%3A//api.soundcloud.com/tracks/47580057

答案 1 :(得分:3)

我使用jquery ajax调用从Soundcloud中获取数据。假设您保存变量permalink_url和client_id:

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

这应记录一系列歌曲。查看此bin以获取参考http://jsbin.com/viviza/4/edit

更新:这个答案很老了。

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

SC对象现在允许直接获取id

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
    })
})

答案 2 :(得分:1)

您还可以从给定的用户ID获取所有曲目。然后使用$ .map()将每个轨道放入一个数组中。用歌曲[i] .id调用SC.stream()从曲目阵列中播放阵列中的随机歌曲。

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();
  });
});

答案 3 :(得分:1)

使用JavaScript从soundcloud歌曲网址中找到曲目数据:

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)
})