SPTPlaylistSnapshot tracksForPlayback returns nil

Trying to get the whole track in a users playlist, it works in an Objective-C demo application, but when I try in Swift, it returns this:

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

I am 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 Objective-C code that works:

 [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 returns (function) in a Swift project instead of all tracks.

Edit: Tried

 println(playl.firstTrackPage.tracksForPlayback()) 

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

+7
ios spotify swift
source share
1 answer

You need to include one or both of the following in the requested areas, if they do not already exist: SPTAuthPlaylistReadScope and SPTAuthPlaylistReadPrivateScope allow access to the user's public and private playlists, respectively.

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

+2
source share

All Articles