7

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

<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

Abubakr Dar
  • 4,078
  • 4
  • 22
  • 28
Vivek Singh
  • 2,453
  • 1
  • 14
  • 27
  • The callback can't be local is the first thing I think of. Could you test this in a public environment? Or route your request to your public ip and open some ports so that your pc will receive the response. – GuyT Jul 16 '15 at 06:01
  • @GuyT yes i have tested it with host url but it's opening a popup and asking for login..although i am passing client id with id – Vivek Singh Jul 16 '15 at 06:03
  • This is expected behaviour(see https://developers.soundcloud.com/docs/api/guide#authentication) – GuyT Jul 16 '15 at 06:10
  • i have already read it if i login to soundcloud site than it say's only a user confirmation button to click but nothing changed in my playlist – Vivek Singh Jul 16 '15 at 06:12
  • i just want , i have a add to playlist button when anyone clicks on it the perticuler track add to player's list – Vivek Singh Jul 16 '15 at 06:13
  • Something like this: https://developers.soundcloud.com/docs/api/reference#playlists ? – GuyT Jul 16 '15 at 06:36
  • yes but can not find any solution – Vivek Singh Jul 16 '15 at 06:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83407/discussion-between-vicky-and-guyt). – Vivek Singh Jul 16 '15 at 08:43
  • put the question on bounty but still not get the suitable answer.... :'( – Vivek Singh Jul 23 '15 at 06:04
  • it's because your question is vague. – GuyT Jul 23 '15 at 06:27
  • don't know vague or not but it is the problem where i got stuck – Vivek Singh Jul 23 '15 at 08:35
  • Ok, but you never responded to my questions: 1. where could we access your code(to be sure it's put in a public space otherwise the callback will never work)? 2. Do you receive any errors in your console? 3. Are you able to recreate the problem in a jsFiddle? – GuyT Jul 23 '15 at 09:21
  • 1.yes you can access this cod in any public space .2.no i dont recieve any error in console just a soundcloud popup opens and asks do u want to create account or ligin with same client id and nothing happens.3.i will try to recreate the problem in js fiddle – Vivek Singh Jul 23 '15 at 10:01
  • So, if it runs in a public space could you provide the URL? – GuyT Jul 23 '15 at 10:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84072/discussion-between-vicky-and-guyt). – Vivek Singh Jul 23 '15 at 11:27
  • Vicky, never ever print your (PHP) errors in a production environment! Disable this by default! – GuyT Jul 23 '15 at 13:04

2 Answers2

1

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

Saty
  • 22,443
  • 7
  • 33
  • 51
HGrover
  • 225
  • 1
  • 10
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....

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.

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.

<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);
      }
    });
});
msj121
  • 2,812
  • 3
  • 28
  • 55