Skip to content
Snippets Groups Projects
Commit d7f169ce authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '34-fix-call-on-me-when-logged-in-from-facebook' into 'master'

Resolve "Fix call on /me when logged in from facebook"

Closes #34

See merge request !31
parents 75722855 20da49ae
No related branches found
No related tags found
1 merge request!31Resolve "Fix call on /me when logged in from facebook"
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "jwilsson/spotify-web-api-php", "name": "jwilsson/spotify-web-api-php",
"version": "5.0.0", "version": "5.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/jwilsson/spotify-web-api-php.git", "url": "https://github.com/jwilsson/spotify-web-api-php.git",
"reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6" "reference": "4ec7242fbaaf2df382d1545f169e8ef8ad7b2006"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/jwilsson/spotify-web-api-php/zipball/44f270a9e8ef9f35089267c58d6bae155fd79ec6", "url": "https://api.github.com/repos/jwilsson/spotify-web-api-php/zipball/4ec7242fbaaf2df382d1545f169e8ef8ad7b2006",
"reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6", "reference": "4ec7242fbaaf2df382d1545f169e8ef8ad7b2006",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
"php": "^7.3 || ^8.0" "php": "^7.3 || ^8.0"
}, },
"require-dev": { "require-dev": {
"php-coveralls/php-coveralls": "^2.0", "php-coveralls/php-coveralls": "^2.5",
"phpunit/phpunit": "^9.4", "phpunit/phpunit": "^9.4",
"squizlabs/php_codesniffer": "^3.0" "squizlabs/php_codesniffer": "^3.0"
}, },
...@@ -52,9 +52,9 @@ ...@@ -52,9 +52,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/jwilsson/spotify-web-api-php/issues", "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": [], "packages-dev": [],
......
...@@ -27,8 +27,8 @@ if ($_SESSION['accessToken']) { ...@@ -27,8 +27,8 @@ if ($_SESSION['accessToken']) {
} }
$options = [ $options = [
'scope' => $SPOTIFY_REQUIRED_SCOPES, 'scope' => $SPOTIFY_REQUIRED_SCOPES,
'auto_refresh' => true, 'auto_refresh' => true,
]; ];
$api = new SpotifyWebAPI\SpotifyWebAPI($options, $session); $api = new SpotifyWebAPI\SpotifyWebAPI($options, $session);
...@@ -39,7 +39,24 @@ $_SESSION['refreshToken'] = $session->getRefreshToken(); ...@@ -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; $topArtistsCount = 40;
$playlistsCount = 24; $playlistsCount = 24;
...@@ -197,7 +214,7 @@ if ($generatePlaylistFromPlaylist) { ...@@ -197,7 +214,7 @@ if ($generatePlaylistFromPlaylist) {
$templateData['playlist'] = createDisplayablePlaylist($newPlaylist); $templateData['playlist'] = createDisplayablePlaylist($newPlaylist);
} else { } else {
$templateData['topArtists'] = $api->getMyTop('artists', ['limit' => $topArtistsCount, 'time_range' => 'short_term'])->items; $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'; require '../template.php';
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="playlist-generator"> <a class="navbar-brand" href="playlist-generator">
<?php if (count($templateData['user']->images)) { ?> <?php if ($templateData['user']['image_url']) { ?>
<img src="<?php echo $templateData['user']->images[0]->url; ?>" class="rounded border" alt="<?php echo $templateData['user']->display_name; ?>" style="max-height: 2rem;"> <img src="<?php echo $templateData['user']['image_url']; ?>" class="rounded border" alt="<?php echo $templateData['user']['display_name']; ?>" style="max-height: 2rem;">
<?php } ?> <?php } ?>
<?php echo $templateData['user']->display_name; ?> <?php echo $templateData['user']['display_name']; ?>
</a> </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"> <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> <span class="navbar-toggler-icon"></span>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item"> <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>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="?logout">Logout</a> <a class="nav-link" href="?logout">Logout</a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment