Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPTPlaylistSnapshot tracksForPlayback returns nil

Tags:

ios

swift

spotify

Trying to get all the track in users playlist, it works in Objective-C demo app but when I try in Swift it returns this:

<SPTPlaylistList: 0x7fca22d72460>: 0-0 of 1 items (Function)

I'm using this code:

SPTPlaylistList.playlistsForUserWithSession(session, callback: { (error, object) -> Void in
            if error == nil {
                var playlists = object as! SPTListPage
                println(playlists)
                SPTPlaylistSnapshot.playlistWithURI(playlists.items[0].uri, accessToken: session.accessToken, callback: { (error:NSError!, obj) -> Void in
                    var playl = obj as! SPTPlaylistSnapshot
                    println(playl.firstTrackPage.tracksForPlayback)
                })
            }

        })

and this is the Objective-C code which is working:

[SPTPlaylistList playlistsForUserWithSession:session callback:^(NSError *error, id object) {
    SPTListPage *aa = object;
    NSLog(@"%@",aa.items);
    [SPTPlaylistSnapshot playlistWithURI:[NSURL URLWithString:@"spotify:user:spotifizr:playlist:3bpGFVfycGnhtcEVb95G98"]
                             accessToken:session.accessToken
                                callback:^(NSError *error, SPTPlaylistSnapshot *object) {
                                    NSLog(@"tracks on page 1 = %@", [object.firstTrackPage tracksForPlayback]);

                                }];
}];

Not sure why it is returning (function) in Swift project instead of all the tracks.

Edit : Tried

println(playl.firstTrackPage.tracksForPlayback()) 

but now it returns nil, although I have 50 tracks in the playlist.

like image 800
Ankit Avatar asked Jun 23 '15 18:06

Ankit


1 Answers

You need to include one or both of the following in your requested scopes, if they aren't already there: SPTAuthPlaylistReadScope and SPTAuthPlaylistReadPrivateScope allows access to a user's public and private playlists, respectively.

See the Authentication and Scopes section of https://github.com/spotify/ios-sdk

like image 115
jaronheard Avatar answered Oct 20 '22 17:10

jaronheard