1. Go to this page and download the library: Download ngiraud/spotify-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ngiraud / spotify-sdk-php example snippets
Route::get('/spotify/redirect', function () {
return Socialite::driver('spotify')
->scopes([
// the list of scopes you want to allow
])
->redirect();
});
Route::get('/spotify/callback', function () {
$user = Socialite::driver('spotify')->user();
return $user->token;
});
use Spotify\Spotify;
$client = Spotify::basic('<client-id>', '<client-secret>');
$seeds = $client->genres()->seeds();
// Returns an instance of Spotify\SingleObjects\Album
$album = $client->albums()->find('<spotify-album-id>');
echo $album->name;
// Returns an instance of Spotify\Support\PaginatedResults
$tracks = $client->albums()->tracks('<spotify-album-id>', ['market' => 'FR', 'limit' => 5]);
echo $tracks->results();
// Returns an instance of Spotify\SingleObjects\Artist
$artist = $client->artists()->find('<spotify-artist-id>');
echo $artist->name;
// Returns an instance of Spotify\Support\PaginatedResults
$albums = $client->artists()->albums('<spotify-artist-id>', ['market' => 'FR', 'limit' => 5]);
echo $albums->results();
// Returns an instance of Spotify\SingleObjects\Audiobook
$audiobook = $client->audiobooks()->find('<spotify-audiobook-id>');
echo $audiobook->name;
// Returns an instance of Spotify\Support\PaginatedResults
$chapters = $client->audiobooks()->chapters('<spotify-audiobook-id>', ['limit' => 5]);
echo $chapters->results();
// Returns an instance of Spotify\SingleObjects\Category
$category = $client->categories()->find('<spotify-category-id>');
echo $category->name;
// Returns an instance of Spotify\Support\PaginatedResults
$categories = $client->categories()->browse();
echo $categories->results();
// Returns an instance of Spotify\SingleObjects\Category
$chapter = $client->chapters()->find('<spotify-chapter-id>');
echo $chapter->name;
// Returns an instance of Spotify\Support\PaginatedResults
$chapters = $client->chapters()->browse();
echo $chapters->results();
// Returns an instance of Spotify\SingleObjects\Episode
$episode = $client->episodes()->find('<spotify-episode-id>');
echo $episode->name;
// Returns an array with the status for each episode
$episodes = $client->episodes()->checkSaved(['<spotify-episode-id>', '<spotify-episode-id>']);
echo $episodes;
// Returns an array of genres
$seeds = $client->genres()->seeds();
echo $seeds;
// Returns an array of markets
$markets = $client->markets()->all();
echo $markets;
// Returns an instance of Spotify\SingleObjects\Player
$player = $client->player()->state();
echo $player->is_playing;
// Returns an instance of Spotify\SingleObjects\Playlist
$playlist = $client->playlists()->find('<spotify-playlist-id>');
echo $playlist->name;
// Returns an instance of Spotify\Support\PaginatedResults
$playlists = $client->playlists()->forCategory('<spotify-category-id>');
echo $playlists->results();
// Returns an instance of Spotify\SingleObjects\Search
$results = $client->search('alice cooper', 'artist');
// $results->artists() is an instance of Spotify\Support\PaginatedResults
// $artist is an instance of Spotify\SingleObjects\Artist
foreach ($results->artists() as $artist) {
echo $artist->name;
}
// Returns an instance of Spotify\SingleObjects\Show
$show = $client->shows()->find('<spotify-show-id>');
echo $show->name;
// Returns an instance of Spotify\Support\PaginatedResults
$episodes = $client->shows()->episodes('<spotify-show-id>');
echo $episodes->results();
// Returns an instance of Spotify\SingleObjects\Track
$track = $client->tracks()->find('<spotify-track-id>');
echo $track->name;
// Returns an instance of Spotify\Support\PaginatedResults
$recommendedTracks = $client->tracks()->recommendations();
echo $recommendedTracks->results();
// Returns an instance of Spotify\SingleObjects\User
$me = $client->users()->me();
echo $me->display_name;
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.