SoundCloud:我需要一个函数来从任何permalink_url中提取artist_url的var以插入到DB中

时间:2013-04-25 09:49:31

标签: api soundcloud

我的permalink_url示例为“https://soundcloud.com/rac/sets/rac-chapter-one”。我需要一个函数来从永久链接url生成artwork_url变量。类似于从Soundcloud文档中提取的此代码,但表示为函数:

<script src="http://connect.soundcloud.com/sdk.js"></script>
SC.initialize({
  client_id: 'YOUR_CLIENT_ID'
});

// permalink to a track
var track_url = 'https://soundcloud.com/rac/sets/rac-chapter-one';

SC.get('/resolve', { url: track_url }, function(track) {
  SC.get('/tracks/' + track.id + '/comments', function(comments) {
    for (var i = 0; i < comments.length; i++) {
      console.log('Someone said: ' + comments[i].body);
    }
  });
});
</script> 

我是一名几乎没有这种编码的玩家,并且会感激任何实际的帮助。干杯!

1 个答案:

答案 0 :(得分:0)

您拥有声音表示中的artwork_url属性:

<script src="http://connect.soundcloud.com/sdk.js"></script>
SC.initialize({
  client_id: 'YOUR_CLIENT_ID'
});

// permalink to a track
var track_url = 'https://soundcloud.com/rac/sets/rac-chapter-one';

SC.get('/resolve', { url: track_url }, function(track) {
  console.log(track.artwork_url);
});
</script>