如何使用javascript创建Soundcloud播放列表(设置)?

时间:2015-07-13 08:56:47

标签: javascript codeigniter soundcloud

我正在尝试将Soundcloud api用于我的应用程序,用户可以在其中创建自己的音轨播放列表。作为测试用例,我正在测试的示例几乎完全取自Soundcloud dev docs。下面是我的代码

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'MY_CLIENT_ID',
  redirect_uri: 'http://localhost.local/~****/sc/callback.html'
});

// initiate auth popup and create new playlist
SC.connect(function() {
    SC.get('/me', function(me) {
        console.log(me.username);
    });

    var tracks = [12573606].map(function(id) { return { id: id }; });
    SC.post('/playlists', {
        playlist: { title: 'My Playlist', tracks: tracks }
    });
});

我已经在google中搜索了很多东西,但没有任何帮助我,实际上我需要临时播放列表所以当用户注销或关闭浏览器播放列表时也会删除。任何帮助都会很明显.. thanx

2 个答案:

答案 0 :(得分:1)

您可以尝试发送client_secret => 'YOUR_CLIENT_SECRET'作为初始化调用的一部分

答案 1 :(得分:1)

看起来在soundcloud中有这样的东西没有临时播放列表,你需要在退出时删除播放列表....

最好的猜测是看看当有人点击您在此处可以找到的删除按钮时,如何格式化您的网址:http://help.soundcloud.com/customer/portal/articles/282512-how-do-i-delete-tracks-from-my-account-我没有帐户,所以我无法测试此部分

创建播放列表的关键是拥有正确的轨道ID。如果您遇到跟踪ID不存在的问题,并且未将其添加到播放列表中,则可能会出现这种情况。

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'MY_CLIENT_ID',
  redirect_uri: 'http://localhost.local/~****/sc/callback.html'
});

// initiate auth popup and create new playlist
SC.connect(function() {
    SC.get('/me', function(me) {
        console.log(me.username);
    });

    var tracks = [12573606].map(function(id) { return { id: id }; });
    SC.post('/playlists', {
        playlist: { title: 'My Playlist', tracks: tracks }
    });
    //As you can see it is a simple array of ids of track
    tracks = [21778201, 22448500, 21928809];
    //To get all playlists remove limit and search each playlist name and grab id
    SC.get('/me/playlists', { limit: 1 }, function(playlist) {
      SC.put(playlist.uri, { playlist: { tracks: tracks } });
    });

    //Then to get all the tracks, please substitute the playlist id for 1234323:
    SC.get('/playlists/1234323', function(playlist) {
      for (var i = 0; i < playlist.tracks.length; i++) {
         console.log(playlist.tracks[i].length);
      }
    });
});