Inherits from SPTListPage : NSObject
Declared in SPTPlaylistList.h

Overview

This class represents a user’s list of playlists, and also contains methods for listing and creating new playlists on behalf of a user.

API Docs: https://developer.spotify.com/web-api/playlist-endpoints/

API Console: https://developer.spotify.com/web-api/console/playlists/

Playlist Guide: https://developer.spotify.com/web-api/working-with-playlists/

Class Methods

createPlaylistWithName:forUser:publicFlag:accessToken:callback:

Create a new playlist and add it to the this playlist list.

+ (void)createPlaylistWithName:(NSString *)name forUser:(NSString *)username publicFlag:(BOOL)isPublic accessToken:(NSString *)accessToken callback:(SPTPlaylistCreationCallback)block

Parameters

name

The name of the newly-created playlist.

username

The user to create the playlist for. (Needs to be the currently authenticated user)

isPublic

Whether the newly-created playlist is public.

accessToken

An authenticated access token. Must be valid and authorized with the playlist-modify-public or playlist-modify-private scope as necessary.

block

The callback block to be fired when playlist creation is completed (or fails).

Declared In

SPTPlaylistList.h

createRequestForCreatingPlaylistWithName:forUser:withPublicFlag:accessToken:error:

Create a request for creating a new playlist and add it to the current users' playlists.

+ (NSURLRequest *)createRequestForCreatingPlaylistWithName:(NSString *)name forUser:(NSString *)username withPublicFlag:(BOOL)isPublic accessToken:(NSString *)accessToken error:(NSError **)error

Parameters

name

The name of the newly-created playlist.

username

The username of the user to create the playlist for. (Must be the current user)

isPublic

Whether the newly-created playlist is public.

accessToken

An authenticated access token. Must be valid and authorized with the playlist-modify-public or playlist-modify-private scope as necessary.

error

An optional pointer to an NSError that will receive the error code if operation failed.

Declared In

SPTPlaylistList.h

createRequestForGettingPlaylistsForUser:withAccessToken:error:

Get the a user’s playlist list.

+ (NSURLRequest *)createRequestForGettingPlaylistsForUser:(NSString *)username withAccessToken:(NSString *)accessToken error:(NSError **)error

Parameters

username

The username of the user to get playlists for.

accessToken

An authenticated access token. Must be valid and authorized with the unspecified or playlist-read-private scope as necessary.

error

An optional pointer to an NSError that will receive the error code if operation failed.

Discussion

Example:

// Getting the first two pages of a playlists for a user
NSURLRequest *playlistrequest = [SPTPlaylistList createRequestForGettingPlaylistsForUser:@"possan" withAccessToken:accessToken error:nil];
[[SPTRequest sharedHandler] performRequest:playlistrequest callback:^(NSError *error, NSURLResponse *response, NSData *data) {
    if (error != nil) { Handle error }
    SPTPlaylistList *playlists = [SPTPlaylistList playlistListFromData:data withResponse:response error:nil];
    NSLog(@"Got possan's playlists, first page: %@", playlists);
    NSURLRequest *playlistrequest2 = [playlists createRequestForNextPageWithAccessToken:accessToken error:nil];
    [[SPTRequest sharedHandler] performRequest:playlistrequest2 callback:^(NSError *error2, NSURLResponse *response2, NSData *data2) {
        if (error2 != nil) { Handle error }
        SPTPlaylistList *playlists2 = [SPTPlaylistList playlistListFromData:data2 withResponse:response2 error:nil];
        NSLog(@"Got possan's playlists, second page: %@", playlists2);
    }];
}];

See: https://developer.spotify.com/web-api/get-list-users-playlists/

Declared In

SPTPlaylistList.h

playlistListFromData:withResponse:error:

Parse the response of an API call into an SPTPlaylistList object

+ (instancetype)playlistListFromData:(NSData *)data withResponse:(NSURLResponse *)response error:(NSError **)error

Parameters

data

The API response data

response

The API response object

error

An optional pointer to an NSError that will receive the error code if operation failed.

Declared In

SPTPlaylistList.h

playlistListFromDecodedJSON:error:

Parse a decoded JSON object into an SPTPlaylistList object

+ (instancetype)playlistListFromDecodedJSON:(id)decodedObject error:(NSError **)error

Parameters

decodedObject

The decoded JSON object

error

An optional pointer to an NSError that will receive the error code if operation failed.

Declared In

SPTPlaylistList.h

playlistsForUser:withAccessToken:callback:

Get the a user’s playlist list.

+ (void)playlistsForUser:(NSString *)username withAccessToken:(NSString *)accessToken callback:(SPTRequestCallback)block

Parameters

username

The username of the user to get playlists for.

accessToken

An authenticated access token. Must be valid and authorized with the unspecified or playlist-read-private scope as necessary.

block

The block to be called when the operation is complete. The block will pass an SPTPlaylistList object on success, otherwise an error.

Declared In

SPTPlaylistList.h