pouler / spotify-artists-api
用于(非官方)Spotify Artists API 的 PHP 包
2.1
2023-01-10 12:06 UTC
Requires
- php: >=8.1
- ext-json: *
- pouler/spotify-login: ^0.3
- symfony/http-client: ^5.4|^6
- symfony/property-access: ^5.4|^6
- symfony/serializer: ^5.4|^6
Requires (Dev)
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.0
Suggests
- pouler/spotify-login: To obtain an access token to be used in API calls
README
这是一个用于(非官方)Spotify Artists API 的 PHP 包装器。
要求
- PHP >=8.1
安装
使用 Composer 安装
composer require pouler/spotify-artists-api
Spotify 登录
您可以通过使用 SpotifyLogin 类来获取访问令牌,此依赖项可以通过以下方式安装:
composer require pouler/spotify-login
有关此项目的更多信息,请参阅:https://github.com/PouleR/spotify-login
使用示例
<?php declare(strict_types=1); require 'vendor/autoload.php'; $httpClient = new \Symfony\Component\HttpClient\CurlHttpClient(); $apiClient = new \PouleR\SpotifyArtistsAPI\SpotifyArtistsAPIClient($httpClient); $artistsApi = new \PouleR\SpotifyArtistsAPI\SpotifyArtistsAPI($apiClient); $loginClient = new \PouleR\SpotifyLogin\SpotifyLoginClient($httpClient); $spotifyLogin = new \PouleR\SpotifyLogin\SpotifyLogin($loginClient); $spotifyLogin->setClientId('clientId'); $spotifyLogin->setDeviceId('deviceId'); // Log in and get the access token $accessToken = $spotifyLogin->login('email@address.com','password'); // Use this token for the artists API $artistsApi->setAccessToken($accessToken); $upcoming = $artistsApi->getUpcomingReleases('artistId'); print_r($upcoming); $realtime = $artistsApi->getRealTimeStatistics('artistId', 'trackId'); print_r($realtime);