pouler / spotify-login

用于登录 Spotify 的 PHP 包

0.3 2022-07-25 12:09 UTC

This package is auto-updated.

Last update: 2024-09-10 12:18:14 UTC


README

这是一个 Spotify 登录的 PHP 包装器。

需求

  • PHP >=8.1

安装

使用 Composer 安装

composer require pouler/spotify-login

编译 .proto 文件

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