calliostro/spotify-web-api-bundle
composer require calliostro/spotify-web-api-bundle
config/packages/calliostro_spotify_web_api.yaml (new PHP format) with your Spotify API credentials:
client_id: '%env(SPOTIFY_CLIENT_ID)%'
client_secret: '%env(SPOTIFY_CLIENT_SECRET)%'
redirect_uri: '%env(SPOTIFY_REDIRECT_URI)%'
use Calliostro\SpotifyWebApiBundle\Service\SpotifyService;
public function showProfile(SpotifyService $spotify)
{
$user = $spotify->getMe();
return response()->json($user);
}
jwilsson/spotify-web-api-php v6 or v7 (no manual version selection required).services.xml with YAML/ENV-based config (e.g., .env or config/packages/).
# config/packages/calliostro_spotify_web_api.yaml
spotify:
client_id: '%env(SPOTIFY_CLIENT_ID)%'
client_secret: '%env(SPOTIFY_CLIENT_SECRET)%'
cache_adapter: 'cache.app' # Optional: Use Symfony cache
SpotifyService directly into controllers/services:
public function __construct(private SpotifyService $spotify) {}
$authUrl = $spotify->getAuthUrl(['scope' => ['user-read-private']]);
// Redirect user to $authUrl, then handle callback with:
$token = $spotify->handleAuthCallback($request);
// Tracks
$tracks = $spotify->search('artist:Taylor Swift', ['type' => 'track']);
// Playlists
$playlists = $spotify->getUserPlaylists('user-id');
cache_adapter):
$spotify->setCache($cacheItemPool); // Manually override if needed
SpotifyService for custom logic:
$spotify->extend(function ($spotify) {
$spotify->getCustomData = function () {
return $this->getMe()->toArray() + ['custom_field' => true];
};
});
// config/services.yaml
services:
App\Listener\SpotifyLogger:
tags:
- { name: kernel.event_listener, event: spotify.api.call, method: onApiCall }
services.xml no longer exists. Use YAML/ENV instead.php bin/console debug:config calliostro_spotify_web_api to validate config.jwilsson/spotify-web-api-php dependency is updated:
composer require jwilsson/spotify-web-api-php:^7.0
$spotify->getClient()->getVersion();
php bin/console cache:clear
# config/packages/calliostro_spotify_web_api.yaml
debug: '%kernel.debug%'
$spotify->setLogger(new \Monolog\Logger('spotify', [...]));
SpotifyClient:
$spotify->setClient(new \SpotifyWebAPI\SpotifyWebAPI([
'client_id' => 'custom-id',
'client_secret' => 'custom-secret',
]));
$spotify->setMiddleware(new class implements \SpotifyWebAPI\Middleware {
public function handle($request, callable $next) { ... }
});
SpotifyService mock in PHPUnit:
$mock = $this->createMock(\SpotifyWebAPI\SpotifyWebAPI::class);
$spotify = new SpotifyService($mock);
.env:
SPOTIFY_CLIENT_ID=your_id_here
SPOTIFY_CLIENT_SECRET=your_secret_here
$container->get('calliostro_spotify_web_api.service');
How can I help you explore Laravel packages today?