Frage

I'm trying to list all the playlists (and their tracks) of the current user on a Spotify integrated app using the API as explains in https://github.com/spotify/apps-tutorial/tree/1.0 .

Is there any way to do this? Or is not supported by now?

Using the 1.X API I did this:

var returnedLibrary;
require(['$api/library#Library'], function(Library) {
  returnedLibrary = Library.forCurrentUser();
});

(From: https://developer.spotify.com/docs/apps/api/1.0/library_.html)

I suppose that my object returnedLibrary has all the playlists for the current user, isn't it? My problem is that I don't know what to do with this returned object and how to iterate through it.

Anyone knows how to access this information?

Thanks,

War es hilfreich?

Lösung

If you are interested in the user's playlists, you can do it like this:

var returnedLibrary;
require(['$api/library#Library'], function(Library) {
  returnedLibrary = Library.forCurrentUser();
  returnedLibrary.playlists.snapshot().done(function(snapshot) {
    for (var i = 0, l = snapshot.length; i < l; i++) {
      var playlist = snapshot.get(i);
      // do something with playlist
    }
  });
});

Andere Tipps

Finally I have achieved my purpose:

var returnedLibrary;
require(['$api/library#Library'], function(Library) {
  returnedLibrary = Library.forCurrentUser();
  returnedLibrary.playlists.snapshot().done(function(snapshot) {
    for (var i = 0, l = snapshot.length; i < l; i++) {
      var playlist = snapshot.get(i);
      aplay._collections();
      aplay.tracks.snapshot().done(function(s){
      selectedPlaylist = s;
      for(k=0;k<s.length;k++){
              s.get(k).name; //Will be the name of that song
      }
      });
    }
  });
});

Nevertheless, I don't know why I have to call aplay._collections(); (it seems is a private method). If I not do this call the tracks property is not set... Any ideas about this?

Thanks!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top