Spotifi Widget

This commit is contained in:
JonatanRek 2020-10-03 18:21:31 +02:00
parent fc3d3d5930
commit 81dcc9da5b
1 changed files with 41 additions and 0 deletions

41
app/plugins/Spotify.php Normal file
View File

@ -0,0 +1,41 @@
<?php
class Spotify extends VirtualDeviceManager {
private $token = "";
private function setToken($token){
$this->token = $token;
}
private function autorize(){
$client_id = '76840e2199e34dcd903d19877bd726dd';
$client_secret = '0f94ed2c0bd64bf791ea13b7e6310ba3';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials&scope=user-read-playback-state' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret)));
$result=curl_exec($ch);
$this->setToken(json_decode($result, true)['access_token']);
echo $result;
}
private function getPlayerData(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.spotify.com/v1/users/byzolscj4vc1p0xcjqykbesn8' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->token));
$result=curl_exec($ch);
echo $result;
}
function fetch($url = 'true')
{
$this->autorize();
$this->getPlayerData();
}
}