diff --git a/app/plugins/Spotify.php b/app/plugins/Spotify.php new file mode 100644 index 0000000..0da044e --- /dev/null +++ b/app/plugins/Spotify.php @@ -0,0 +1,41 @@ +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(); + } +}