pouler / spotify-login
用于登录 Spotify 的 PHP 包
0.3
2022-07-25 12:09 UTC
Requires
- php: >=8.1
- ext-json: *
- google/protobuf: ^3.15
- 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
README
这是一个 Spotify 登录的 PHP 包装器。
需求
- PHP >=8.1
安装
使用 Composer 安装
composer require pouler/spotify-login
编译 .proto 文件
- 最初来源于此仓库: https://github.com/librespot-org/librespot-java/tree/dev/lib/src/main/proto/spotify/login5/v3
- 请确保已安装 protoc 编译器
- .proto 文件用于生成 PHP 类
protoc --php_out=./generated --proto_path=./proto \ proto/spotify/login5/v3/login5.proto \ proto/spotify/login5/v3/user_info.proto \ proto/spotify/login5/v3/client_info.proto \ proto/spotify/login5/v3/challenges/code.proto \ proto/spotify/login5/v3/challenges/hashcash.proto \ proto/spotify/login5/v3/credentials/credentials.proto \ proto/spotify/login5/v3/identifiers/identifiers.proto
示例用法
<?php declare(strict_types=1); require 'vendor/autoload.php'; $httpClient = new \Symfony\Component\HttpClient\CurlHttpClient(); $client = new \PouleR\SpotifyLogin\SpotifyLoginClient($httpClient); $spotifyLogin = new \PouleR\SpotifyLogin\SpotifyLogin($client); $spotifyLogin->setClientId('clientId'); $spotifyLogin->setDeviceId('deviceId'); // Log in and get the access token $token = $spotifyLogin->login('email@address.com','password'); // Refresh token $newToken = $spotifyLogin->refreshToken($token->getUsername(), $token->getRefreshToken()); print_r($newToken);