문제

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,

도움이 되었습니까?

해결책

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
    }
  });
});

다른 팁

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top