Ejemplo n.º 1
0
require './vendor/autoload.php';
require './src/functions.php';
require_once './src/workflows.php';
$w = new Workflows('com.vdesabou.spotify.mini.player');
//
// Read settings from JSON
//
$settings = getSettings($w);
$oauth_client_id = $settings->oauth_client_id;
$oauth_client_secret = $settings->oauth_client_secret;
$oauth_redirect_uri = $settings->oauth_redirect_uri;
try {
    $session = new SpotifyWebAPI\Session($oauth_client_id, $oauth_client_secret, $oauth_redirect_uri);
    if (!empty($_GET['code'])) {
        // Request a access token using the code from Spotify
        $ret = $session->requestToken($_GET['code']);
        if ($ret == true) {
            $api = new SpotifyWebAPI\SpotifyWebAPI();
            // Set the code on the API wrapper
            $api->setAccessToken($session->getAccessToken());
            $user = $api->me();
            $ret = updateSetting($w, 'oauth_access_token', $session->getAccessToken());
            if ($ret == false) {
                echo "There was an error when updating settings";
                exec("kill -9 \$(ps -efx | grep \"php -S localhost:15298\"  | grep -v grep | awk '{print \$2}')");
                return;
            }
            $ret = updateSetting($w, 'oauth_expires', time());
            if ($ret == false) {
                echo "There was an error when updating settings";
                exec("kill -9 \$(ps -efx | grep \"php -S localhost:15298\"  | grep -v grep | awk '{print \$2}')");