pouler/spotify-login

PHP Package for logging in to Spotify

0.3 2022-07-25 12:09 UTC

This package is auto-updated.

Last update: 2024-04-10 11:32:31 UTC


README

This is a PHP wrapper for a Spotify login.

Requirements

  • PHP >=8.1

Installation

Install it using Composer:

composer require pouler/spotify-login

Compiling .proto files

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

Example usage

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