pouler / spotify-artists-api

用于(非官方)Spotify Artists API 的 PHP 包

2.1 2023-01-10 12:06 UTC

This package is auto-updated.

Last update: 2024-09-10 15:27:15 UTC


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);