This is a PHP wrapper for Spotify's Web API. It includes the following:
- Helper methods for all API methods:
- Information about artists, albums, tracks, and users.
- Spotify catalog search.
- Playlist and user music library management.
- Music featured by Spotify.
- Authorization flow helpers.
- PSR-4 autoloading support.
- PHP 5.5 or greater.
- PHP cURL extension (Usually included with PHP).
Add spotify-web-api-php
as a dependency to your composer.json
:
"require": {
"jwilsson/spotify-web-api-php": "^1.0.0"
}
For more instructions, please refer to the documentation.
Add albums to the current user's library
$api->addMyAlbums([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
]);
Add tracks to the current user's library
$api->addMyTracks([
'1id6H6vcwSB9GGv9NXh5cl',
'3mqRLlD9j92BBv1ueFhJ1l',
]);
Add tracks to a user's playlist
$api->addUserPlaylistTracks('username', 'playlist_id', [
'1id6H6vcwSB9GGv9NXh5cl',
'3mqRLlD9j92BBv1ueFhJ1l',
]);
Create a new playlist for a user
$api->createUserPlaylist('username', [
'name' => 'My shiny playlist',
]);
Check if the current user follows a user or artist
$follows = $api->currentUserFollows('user', [
'spotify',
'spotify_france',
]);
var_dump($follows);
Delete albums from the current user's library
$api->deleteMyAlbums([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a'
]);
Delete tracks from the current user's library
$api->deleteMyTracks([
'1id6H6vcwSB9GGv9NXh5cl',
'3mqRLlD9j92BBv1ueFhJ1l',
]);
Delete tracks from a user's playlist
$tracks = [
['id' => '1id6H6vcwSB9GGv9NXh5cl'],
['id' => '3mqRLlD9j92BBv1ueFhJ1l'],
];
$api->deleteUserPlaylistTracks('username', 'playlist_id', $tracks, 'snapshot_id');
Follow an artist or user
$api->followArtistsOrUsers('artist', [
'74ASZWbe4lXaubB36ztrGX',
'2t9yJDJIEtvPmr2iRIdqBf',
]);
Follow a playlist
$api->followPlaylist('username', 'playlist_id');
Get an album
$album = $api->getAlbum('7u6zL7kqpgLPISZYXNTgYk');
print_r($album);
Get multiple albums
$albums = $api->getAlbums([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a',
]);
print_r($albums);
Get all tracks from an album
$tracks = $api->getAlbumTracks('1oR3KrPIp4CbagPa3PhtPp');
print_r($tracks);
Get an artist
$artist = $api->getArtist('36QJpDe2go2KgaRleHCDTp');
print_r($artist);
Get an artist's related artists
$artists = $api->getArtistRelatedArtists('36QJpDe2go2KgaRleHCDTp');
print_r($artists);
Get multiple artists
$artists = $api->getArtists([
'6v8FB84lnmJs434UJf2Mrm',
'6olE6TJLqED3rqDCT0FyPh',
]);
print_r($artists);
Get all albums by an artist
$albums = $api->getArtistAlbums('6v8FB84lnmJs434UJf2Mrm');
print_r($albums);
Get an artist's top tracks in a country
$tracks = $api->getArtistTopTracks('6v8FB84lnmJs434UJf2Mrm', [
'country' => 'se',
]);
print_r($tracks);
Get track audio features
$features = $api->getAudioFeatures([
'0eGsygTp906u18L0Oimnem',
'1lDWb6b6ieDQ2xT7ewTC3G',
]);
print_r($features);
Get Spotify list of categories
$categories = $api->getCategoriesList([
'country' => 'se',
]);
print_r($categories);
Get Spotify category
$category = $api->getCategory('dinner', [
'country' => 'se',
]);
print_r($category);
Get playlists of a Spotify category
$playlists = $api->getCategoryPlaylists('dinner', [
'country' => 'se',
]);
print_r($playlists);
Get Spotify featured playlists
$playlists = $api->getFeaturedPlaylists();
print_r($playlists);
Get a list of possible seed genres
$genres = $api->getGenreSeeds();
print_r($genres);
Get new releases
$items = $api->getNewReleases([
'country' => 'se',
]);
print_r($items);
Get the current user's playlists
$playlists = $api->getMyPlaylists();
print_r($playlists);
Get the current user's saved albums
$albums = $api->getMySavedAlbums();
print_r($albums);
Get the current user's top tracks or artists
$tracks = $api->getMyTop('tracks', [
'limit' => 10,
]);
print_r($tracks);
Get recommendations based on artists, tracks, or genres
$recommendations = $api->getRecommendations([
'seed_tracks' => ['0eGsygTp906u18L0Oimnem', '1lDWb6b6ieDQ2xT7ewTC3G'],
]);
print_r($recommendations);
Get the current user's saved tracks
$tracks = $api->getMySavedTracks();
print_r($tracks);
Get a track
$track = $api->getTrack('7EjyzZcbLxW7PaaLua9Ksb');
print_r($track);
Get multiple tracks
$tracks = $api->getTracks([
'0eGsygTp906u18L0Oimnem',
'1lDWb6b6ieDQ2xT7ewTC3G',
]);
print_r($tracks);
Get a user
$user = $api->getUser('username');
print_r($user);
Get a user's playlists
$playlists = $api->getUserPlaylists('username');
print_r($playlists);
Get a specific playlist
$playlist = $api->getUserPlaylist('username', '606nLQuR41ZaA2vEZ4Ofb8');
print_r($playlist);
Get all tracks in a user's playlist
$tracks = $api->getUserPlaylistTracks('username', '606nLQuR41ZaA2vEZ4Ofb8');
print_r($tracks);
Get the currently authenticated user
$user = $api->me();
print_r($user);
See if the current user's albums contains the specified ones
$contains = $api->myAlbumsContains([
'1oR3KrPIp4CbagPa3PhtPp',
'6lPb7Eoon6QPbscWbMsk6a'
]);
var_dump($contains);
See if the current user's tracks contains the specified tracks
$contains = $api->myTracksContains([
'0eGsygTp906u18L0Oimnem',
'1lDWb6b6ieDQ2xT7ewTC3G',
]);
var_dump($contains);
Reorder the tracks in a user's playlist
$api->reorderUserPlaylistTracks('username', 'playlist_id', [
'range_start' => 1,
'range_length' => 5,
'insert_before' => 10,
'snapshot_id' => 'GLiKqjND5IDWQCO9PwtLvHVjRXYYjEvpoliIQ5/gK7M5BMcxJ7rnGMGTKbmDRgU3',
]);
Replace all tracks in a user's playlist with new ones
$api->replaceUserPlaylistTracks('username', 'playlist_id', [
'0eGsygTp906u18L0Oimnem',
'1lDWb6b6ieDQ2xT7ewTC3G',
]);
Search for an album
$albums = $api->search('blur', 'album');
print_r($albums);
Search for an artist
$artists = $api->search('blur', 'artist');
print_r($artists);
Search for a track
$tracks = $api->search('song 2', 'track');
print_r($tracks);
Search with a limit
$tracks = $api->search('song 2', 'track', [
'limit' => 5,
]);
print_r($tracks);
Search for tracks in a specific market
$tracks = $api->search('song 2', 'track', [
'market' => 'se',
]);
print_r($tracks);
Update a user's playlist
$api->updateUserPlaylist('username', 'playlist_id', [
'name' => 'New name',
]);
Unfollow an artist or user
$api->unfollowArtistsOrUsers('user', [
'spotify',
'spotify_france',
]);
Unfollow a playlist
$api->unfollowPlaylist('username', 'playlist_id');
Check if a user is following a playlist
$users = [
'user1',
'user2',
];
$api->userFollowsPlaylist('owner_id', 'playlist_id', [
'ids' => $users,
]);
For more examples, please see the homepage.
MIT license. Please see LICENSE.md for more information.