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

时间:2022-04-24 01:22:45

I am trying to use Soundcloud api for my application where user can create his/her own playlist of track . As a test case the example I am testing is almost exactly taken from the Soundcloud dev docs. below is my code

我正在尝试将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 }
    });
});

I already searched so many thing's in google but nothing helped me, actually i need temporary playlist so when user logout or close the browser playlist also delete . Any help would be appreciable.. thanx

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

2 个解决方案

#1


1  

Can you try sending the client_secret => 'YOUR_CLIENT_SECRET' as part of the initialize call

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

#2


1  

It doesn't look like there is such a thing in soundcloud to have a temporary playlist, you will need to delete the playlist on exit....

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

The best guess would be to see how to format your url to match when someone clicks on the delete button which you can find here: http://help.soundcloud.com/customer/portal/articles/282512-how-do-i-delete-tracks-from-my-account- I don't have an account so I can't test this part.

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

The key to creating the playlist is having the right track ids. It is possible if your having an issue that the track id doesn't exist and so it doesn't get added to the playlist.

创建播放列表的关键是拥有正确的轨道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);
      }
    });
});

#1


1  

Can you try sending the client_secret => 'YOUR_CLIENT_SECRET' as part of the initialize call

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

#2


1  

It doesn't look like there is such a thing in soundcloud to have a temporary playlist, you will need to delete the playlist on exit....

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

The best guess would be to see how to format your url to match when someone clicks on the delete button which you can find here: http://help.soundcloud.com/customer/portal/articles/282512-how-do-i-delete-tracks-from-my-account- I don't have an account so I can't test this part.

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

The key to creating the playlist is having the right track ids. It is possible if your having an issue that the track id doesn't exist and so it doesn't get added to the playlist.

创建播放列表的关键是拥有正确的轨道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);
      }
    });
});