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

Improve call on /me (catch exception, update composer dependencies) when login from facebook

parent 75722855
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 @@
"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": [],
......
......@@ -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';
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment