Skip to content

vorenusCoA/spotify-web-api-php

 
 

Repository files navigation

Spotify Web API PHP

Build Status Coverage Status Latest Stable Version

This is a PHP implementation of the Spotify 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.

Requirements

Installation

Add spotify-web-api-php as a dependency to your composer.json:

"require": {
    "jwilsson/spotify-web-api-php": "0.9.*"
}

For more instructions, please refer to the documentation.

Examples

Add tracks to a user's library

$api->addMyTracks(array('1oR3KrPIp4CbagPa3PhtPp', '6lPb7Eoon6QPbscWbMsk6a'));

Add tracks to a user's playlist

$api->addUserPlaylistTracks('username', 'playlist_id', array(
    '1oR3KrPIp4CbagPa3PhtPp',
    '6lPb7Eoon6QPbscWbMsk6a'
));

Create a new playlist for a user

$api->createUserPlaylist('username', array(
    'name' => 'My shiny playlist'
));

Delete tracks from a user's library

$api->deleteMyTracks(array(
    '1oR3KrPIp4CbagPa3PhtPp',
    '6lPb7Eoon6QPbscWbMsk6a'
));

Delete tracks from a user's playlist

$tracks = array(
    array('id' => '1oR3KrPIp4CbagPa3PhtPp'),
    array('id' => '6lPb7Eoon6QPbscWbMsk6a')
);

$api->deleteUserPlaylistTracks('username', 'playlist_id', $tracks, 'snapshot_id');

Get a album

$album = $api->getAlbum('7u6zL7kqpgLPISZYXNTgYk');

print_r($album);

Get multiple albums

$albums = $api->getAlbums(array(
    '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(array(
    '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', 'se');

print_r($tracks);

Get Spotify featured playlists

$playlists = $api->getFeaturedPlaylists();

print_r($playlists);

Get Spotify list of categories

$categories = $api->getCategoriesList(array(
    'country' => 'se'
));

print_r($categories);

Get Spotify category

$category = $api->getCategory('dinner', array(
    'country' => 'se'
));

print_r($category);

Get playlists of a Spotify category

$playlists = $api->getCategoryPlaylists('dinner', array(
    'country' => 'se'
));

print_r($playlists);

Get new releases

$items = $api->getNewReleases(array(
    'country' => 'se'
));

print_r($items);

Get a 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(array(
    '0eGsygTp906u18L0Oimnem',
    '1lDWb6b6ieDQ2xT7ewTC3G'
));

print_r($tracks);

Get a user

$user = $api->getUser('username');

print_r($user);

Get 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 a user's tracks contains the specified tracks

$contains = $api->myTracksContains(array(
    '0eGsygTp906u18L0Oimnem',
    '1lDWb6b6ieDQ2xT7ewTC3G'
));

var_dump($contains);

Reorder the tracks in a user's playlist

$api->reorderUserPlaylistTracks('username', 'playlist_id', array(
    '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', array(
    '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', array(
    'limit' => 5
));

print_r($tracks);

Search for tracks in a specific market

$tracks = $api->search('song 2', 'track', array(
    'market' => 'se'
));

print_r($tracks);

Update a user's playlist

$api->updateUserPlaylist('username', 'playlist_id', array(
    'name' => 'New name'
));

Check if a user is following a playlist

$users = array(
    'user1',
    'user2'
);

$api->userFollowsPlaylist('owner_id', 'playlist_id', array(
    'ids' => $users
));

Follow and unfollow an artist or user

$api->followArtistsOrUsers('artist', '74ASZWbe4lXaubB36ztrGX');

$api->unfollowArtistsOrUsers('artist', '74ASZWbe4lXaubB36ztrGX');

$api->followArtistsOrUsers('artist', array(
    '74ASZWbe4lXaubB36ztrGX',
    '2t9yJDJIEtvPmr2iRIdqBf'
));

$api->followArtistsOrUsers('user', array(
    'spotify',
    'spotify_france'
));

$api->unfollowArtistsOrUsers('user', array(
    'spotify',
    'spotify_france'
));

Check if the current user follows a user or artist

$follows = $api->currentUserFollows('user', array(
    'spotify',
    'spotify_france'
));

var_dump($follows);

$follows = $api->currentUserFollows('artist', '74ASZWbe4lXaubB36ztrGX');

var_dump($follows);

Follow a playlist

$api->followPlaylist('username', 'playlist_id');

Unfollow a playlist

$api->unfollowPlaylist('username', 'playlist_id');

For more examples, please see the homepage.

License

MIT license. Please see LICENSE.md for more information.

About

A PHP implementation of Spotify's Web API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%