diff --git a/composer.lock b/composer.lock index 83eba841e6334d614e84e541c816052b574677e2..bead1480ee1a04dcf33fdeeba6034da2893afb88 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "jwilsson/spotify-web-api-php", - "version": "5.0.0", + "version": "5.0.3", "source": { "type": "git", "url": "https://github.com/jwilsson/spotify-web-api-php.git", - "reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6" + "reference": "4ec7242fbaaf2df382d1545f169e8ef8ad7b2006" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jwilsson/spotify-web-api-php/zipball/44f270a9e8ef9f35089267c58d6bae155fd79ec6", - "reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6", + "url": "https://api.github.com/repos/jwilsson/spotify-web-api-php/zipball/4ec7242fbaaf2df382d1545f169e8ef8ad7b2006", + "reference": "4ec7242fbaaf2df382d1545f169e8ef8ad7b2006", "shasum": "" }, "require": { @@ -25,7 +25,7 @@ "php": "^7.3 || ^8.0" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.0", + "php-coveralls/php-coveralls": "^2.5", "phpunit/phpunit": "^9.4", "squizlabs/php_codesniffer": "^3.0" }, @@ -52,9 +52,9 @@ ], "support": { "issues": "https://github.com/jwilsson/spotify-web-api-php/issues", - "source": "https://github.com/jwilsson/spotify-web-api-php/tree/5.0.0" + "source": "https://github.com/jwilsson/spotify-web-api-php/tree/5.0.3" }, - "time": "2021-05-14T20:15:37+00:00" + "time": "2022-01-15T12:55:35+00:00" } ], "packages-dev": [], diff --git a/public/index.php b/public/index.php index db187e2937630e82582c285ba440d9d9910a2e35..59740b12f15c6407a57ebf4c9b21a1dd1bcf89ee 100644 --- a/public/index.php +++ b/public/index.php @@ -27,8 +27,8 @@ if ($_SESSION['accessToken']) { } $options = [ - 'scope' => $SPOTIFY_REQUIRED_SCOPES, - 'auto_refresh' => true, + 'scope' => $SPOTIFY_REQUIRED_SCOPES, + 'auto_refresh' => true, ]; $api = new SpotifyWebAPI\SpotifyWebAPI($options, $session); @@ -39,7 +39,24 @@ $_SESSION['refreshToken'] = $session->getRefreshToken(); // ################################################################ -$user = $api->me(); +$user = [ + 'id' => '', + 'image_url' => '', + 'display_name' => '', + 'profile_url' => '', +]; +try { + $me = $api->me(); + + $user = [ + 'id' => $me->id, + 'image_url' => \count($me->images) ? $me->images[0]->url : '', + 'display_name' => $me->display_name, + 'profile_url' => $me->external_urls->spotify, + ]; +} catch (Exception $ex) { + error_log($ex->getMessage()); +} $topArtistsCount = 40; $playlistsCount = 24; @@ -197,7 +214,7 @@ if ($generatePlaylistFromPlaylist) { $templateData['playlist'] = createDisplayablePlaylist($newPlaylist); } else { $templateData['topArtists'] = $api->getMyTop('artists', ['limit' => $topArtistsCount, 'time_range' => 'short_term'])->items; - $templateData['playlists'] = $api->getUserPlaylists($user->id, ['limit' => $playlistsCount])->items; + $templateData['playlists'] = $api->getUserPlaylists($user['id'], ['limit' => $playlistsCount])->items; } require '../template.php'; diff --git a/template.php b/template.php index 2b1f3377e75dc153d94c604b195e05677a20d705..00a5d25348411bf0aa0d93ed95d2b31db93218d0 100644 --- a/template.php +++ b/template.php @@ -17,10 +17,10 @@ <nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <div class="container-fluid"> <a class="navbar-brand" href="playlist-generator"> - <?php if (count($templateData['user']->images)) { ?> - <img src="<?php echo $templateData['user']->images[0]->url; ?>" class="rounded border" alt="<?php echo $templateData['user']->display_name; ?>" style="max-height: 2rem;"> + <?php if ($templateData['user']['image_url']) { ?> + <img src="<?php echo $templateData['user']['image_url']; ?>" class="rounded border" alt="<?php echo $templateData['user']['display_name']; ?>" style="max-height: 2rem;"> <?php } ?> - <?php echo $templateData['user']->display_name; ?> + <?php echo $templateData['user']['display_name']; ?> </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> @@ -28,7 +28,7 @@ <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> <li class="nav-item"> - <a class="nav-link" href="<?php echo $templateData['user']->external_urls->spotify; ?>">Profile</a> + <a class="nav-link" href="<?php echo $templateData['user']['profile_url']; ?>">Profile</a> </li> <li class="nav-item"> <a class="nav-link" href="?logout">Logout</a>