There are lots of operations involving user's playlists that can be performed. Remember to request the correct scopes beforehand.
$playlists = $api->getUserPlaylists('USER_ID', [
'limit' => 5
]);
foreach ($playlists->items as $playlist) {
echo '<a href="' . $playlist->external_urls->spotify . '">' . $playlist->name . '</a> <br>';
}
$playlist = $api->getPlaylist('PLAYLIST_ID');
echo $playlist->name;
$playlistImage = $api->getPlaylistImage('PLAYLIST_ID');
$playlistTracks = $api->getPlaylistTracks('PLAYLIST_ID');
foreach ($playlistTracks->items as $track) {
$track = $track->track;
echo '<a href="' . $track->external_urls->spotify . '">' . $track->name . '</a> <br>';
}
$api->createPlaylist('USER_ID', [
'name' => 'My shiny playlist'
]);
$api->updatePlaylist('PLAYLIST_ID', [
'name' => 'New name'
]);
$imageData = base64_encode(file_get_contents('image.jpg'));
$api->updatePlaylistImage('PLAYLIST_ID', $imageData);
$api->addPlaylistTracks('PLAYLIST_ID', [
'TRACK_ID',
'EPISODE_URI'
]);
$tracks = [
'tracks' => [
['uri' => 'TRACK_ID'],
['uri' => 'EPISODE_URI'],
],
];
$api->deletePlaylistTracks('PLAYLIST_ID', $tracks, 'SNAPSHOT_ID');
$trackOptions = [
'positions' => [
5,
12,
],
];
$api->deletePlaylistTracks('PLAYLIST_ID', $trackOptions, 'SNAPSHOT_ID');
$api->replacePlaylistTracks('PLAYLIST_ID', [
'TRACK_ID',
'EPISODE_URI'
]);
$api->reorderPlaylistTracks('PLAYLIST_ID', [
'range_start' => 1,
'range_length' => 5,
'insert_before' => 10,
'snapshot_id' => 'SNAPSHOT_ID'
]);
Please see the method reference for more available options for each method.