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

Merge branch '1-add-minimal-web-application' into 'master'

Resolve "Add minimal web application"

Closes #1

See merge request !1
parents 33827c80 36b998e3
No related branches found
No related tags found
1 merge request!1Resolve "Add minimal web application"
/parameters.php
/vendor
# spotify # spotify
# Register app
<https://developer.spotify.com/dashboard/applications>
App name:
Spotify playlist manager
Add description:
Application to help create/update playlists from other playlists or selected artists/tracks.
Something like "radios", but more personalized.
Client ID:
41597dbeb0b3403caa28e7e428e0c9b2
Client Secret:
<hidden>
{
"require": {
"jwilsson/spotify-web-api-php": "^5.0"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6c79ee0e956770840720f3445b9351d9",
"packages": [
{
"name": "jwilsson/spotify-web-api-php",
"version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/jwilsson/spotify-web-api-php.git",
"reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jwilsson/spotify-web-api-php/zipball/44f270a9e8ef9f35089267c58d6bae155fd79ec6",
"reference": "44f270a9e8ef9f35089267c58d6bae155fd79ec6",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": "^7.3 || ^8.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.0",
"phpunit/phpunit": "^9.4",
"squizlabs/php_codesniffer": "^3.0"
},
"type": "library",
"autoload": {
"psr-4": {
"SpotifyWebAPI\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jonathan Wilsson",
"email": "jonathan.wilsson@gmail.com"
}
],
"description": "A PHP wrapper for Spotify's Web API.",
"homepage": "https://github.com/jwilsson/spotify-web-api-php",
"keywords": [
"spotify"
],
"support": {
"issues": "https://github.com/jwilsson/spotify-web-api-php/issues",
"source": "https://github.com/jwilsson/spotify-web-api-php/tree/5.0.0"
},
"time": "2021-05-14T20:15:37+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.0.0"
}
<?php
$parametersFile = __DIR__.'/parameters.php';
if (!is_file($parametersFile)) {
die('Missing parameters file: '.$parametersFile);
}
require $parametersFile;
<?php
$CLIENT_ID = '';
$CLIENT_SECRET = '';
$REDIRECT_URI = '';
<?php
session_start();
require '../vendor/autoload.php';
require '../config.php';
$session = new SpotifyWebAPI\Session(
$CLIENT_ID,
$CLIENT_SECRET,
$REDIRECT_URI
);
$state = $session->generateState();
$_SESSION['state'] = $state;
$options = [
'scope' => [
'playlist-read-private',
'playlist-modify-private',
'user-read-private',
],
'state' => $state,
];
header('Location: ' . $session->getAuthorizeUrl($options));
die();
<?php
session_start();
require '../vendor/autoload.php';
require '../config.php';
$session = new SpotifyWebAPI\Session(
$CLIENT_ID,
$CLIENT_SECRET,
$REDIRECT_URI
);
$storedState = $_SESSION['state'];
$state = $_GET['state'];
if ($state !== $storedState) {
header('Location: auth.php');
}
$session->requestAccessToken($_GET['code']);
$_SESSION['accessToken'] = $session->getAccessToken();
$_SESSION['refreshToken'] = $session->getRefreshToken();
header('Location: index.php');
die();
This diff is collapsed.
<?php
session_start();
require '../vendor/autoload.php';
require '../config.php';
$accessToken = '';
if (isset($_SESSION['accessToken'])) {
$accessToken = $_SESSION['accessToken'];
}
if (!$accessToken) {
header('Location: auth.php');
die();
}
$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setAccessToken($accessToken);
$user = $api->me();
$templateData = [];
$templateData['user'] = $user;
$templateData['userImageUrl'] = '';
if ($user->images[0]) {
$templateData['userImageUrl'] = $user->images[0]->url;
}
$templateData['playlists'] = $api->getUserPlaylists($user->id)->items;
require '../template.php';
This diff is collapsed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Spotify playlist generator</title>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" media="all" />
<link rel="stylesheet" href="css/styles.css" type="text/css" media="all" />
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
</head>
<body class="m-2">
<div class="row">
<div class="col-md-2">
<div class="card">
<img src="<?php echo $templateData['userImageUrl']; ?>" class="card-img-top" alt="<?php echo $templateData['user']->display_name; ?>">
<div class="card-body">
<h5 class="card-title"><?php echo $templateData['user']->display_name; ?></h5>
<a href="<?php echo $templateData['user']->external_urls->spotify; ?>" class="btn btn-primary">View profile</a>
</div>
</div>
</div>
<div class="col-md-10">
<div class="list-group">
<?php
foreach ($templateData['playlists'] as $playlist) {
echo '<a href="' . $playlist->external_urls->spotify . '" class="list-group-item list-group-item-action">' . $playlist->name . '</a>';
}
?>
</div>
</div>
</div>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment