implemented one-way switching of php via javascript.

This commit is contained in:
Joshua Ashton
2025-02-01 14:00:38 -07:00
parent a6a6831f39
commit c9ad259a65
9 changed files with 820 additions and 111 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
{ {
"require": { "require": {
"vlucas/phpdotenv": "^5.6" "vlucas/phpdotenv": "^5.6",
"aslamhus/spotify-client": "^1.2"
} }
} }
+639 -1
View File
@@ -4,8 +4,50 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "108be68e4e2b97fed51d36a10eed0849", "content-hash": "1d873aeac830113b36cf190390c9b4f4",
"packages": [ "packages": [
{
"name": "aslamhus/spotify-client",
"version": "v1.2.8",
"source": {
"type": "git",
"url": "https://github.com/aslamhus/Spotify.git",
"reference": "f4d3af22a1b383fa46437f298dfd91fb2ffe42ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aslamhus/Spotify/zipball/f4d3af22a1b383fa46437f298dfd91fb2ffe42ad",
"reference": "f4d3af22a1b383fa46437f298dfd91fb2ffe42ad",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^7.8",
"guzzlehttp/psr7": "^2.6"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"vlucas/phpdotenv": "^5.6"
},
"type": "library",
"autoload": {
"psr-4": {
"Aslamhus\\SpotifyClient\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"authors": [
{
"name": "aslamhus",
"email": "aslam.percy.husain@gmail.com"
}
],
"description": "A PHP library for the spotify API",
"support": {
"issues": "https://github.com/aslamhus/Spotify/issues",
"source": "https://github.com/aslamhus/Spotify/tree/v1.2.8"
},
"time": "2024-01-17T02:35:45+00:00"
},
{ {
"name": "graham-campbell/result-type", "name": "graham-campbell/result-type",
"version": "v1.1.3", "version": "v1.1.3",
@@ -68,6 +110,331 @@
], ],
"time": "2024-07-20T21:45:45+00:00" "time": "2024-07-20T21:45:45+00:00"
}, },
{
"name": "guzzlehttp/guzzle",
"version": "7.9.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d281ed313b989f213357e3be1a179f02196ac99b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b",
"reference": "d281ed313b989f213357e3be1a179f02196ac99b",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/promises": "^1.5.3 || ^2.0.3",
"guzzlehttp/psr7": "^2.7.0",
"php": "^7.2.5 || ^8.0",
"psr/http-client": "^1.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0"
},
"provide": {
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"ext-curl": "*",
"guzzle/client-integration-tests": "3.0.2",
"php-http/message-factory": "^1.1",
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"suggest": {
"ext-curl": "Required for CURL handler support",
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "jeremeamia@gmail.com",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle is a PHP HTTP client library",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"psr-18",
"psr-7",
"rest",
"web service"
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.9.2"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
"type": "tidelift"
}
],
"time": "2024-07-24T11:22:20+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/f9c436286ab2892c7db7be8c8da4ef61ccf7b455",
"reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/2.0.4"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
"type": "tidelift"
}
],
"time": "2024-10-17T10:06:22+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.7.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201",
"reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201",
"shasum": ""
},
"require": {
"php": "^7.2.5 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"ralouphie/getallheaders": "^3.0"
},
"provide": {
"psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"http-interop/http-factory-tests": "0.9.0",
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
},
"type": "library",
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": false
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "George Mponos",
"email": "gmponos@gmail.com",
"homepage": "https://github.com/gmponos"
},
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com",
"homepage": "https://github.com/Nyholm"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://github.com/sagikazarmark"
},
{
"name": "Tobias Schultze",
"email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com",
"homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"psr-7",
"request",
"response",
"stream",
"uri",
"url"
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.7.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://github.com/Nyholm",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
"type": "tidelift"
}
],
"time": "2024-07-18T11:15:46+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.9.3", "version": "1.9.3",
@@ -143,6 +510,277 @@
], ],
"time": "2024-07-20T21:41:07+00:00" "time": "2024-07-20T21:41:07+00:00"
}, },
{
"name": "psr/http-client",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-client.git",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"psr/http-message": "^1.0 || ^2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP clients",
"homepage": "https://github.com/php-fig/http-client",
"keywords": [
"http",
"http-client",
"psr",
"psr-18"
],
"support": {
"source": "https://github.com/php-fig/http-client"
},
"time": "2023-09-23T14:17:50+00:00"
},
{
"name": "psr/http-factory",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
"reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"shasum": ""
},
"require": {
"php": ">=7.1",
"psr/http-message": "^1.0 || ^2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "PSR-17: Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"message",
"psr",
"psr-17",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-factory"
},
"time": "2024-04-15T12:06:14+00:00"
},
{
"name": "psr/http-message",
"version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/2.0"
},
"time": "2023-04-04T09:54:51+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/ralouphie/getallheaders.git",
"reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
"reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
"files": [
"src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ralph Khattar",
"email": "ralph.khattar@gmail.com"
}
],
"description": "A polyfill for getallheaders.",
"support": {
"issues": "https://github.com/ralouphie/getallheaders/issues",
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
},
"time": "2019-03-08T08:55:37+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.5.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": {
"dev-main": "3.5-dev"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:20:29+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.31.0", "version": "v1.31.0",
+39
View File
@@ -0,0 +1,39 @@
<?php
function get_core()
{
$albums = [
array('name' => 'Abyss', 'artist' => 'Pastel Ghost', 'link' => 'https://open.spotify.com/album/2FQieUp8BxPN7OR8fE76TE'),
array('name' => 'Golden Age - The 4th Album', 'artist' => 'NCT 127', 'link' => 'https://open.spotify.com/album/5mUo2e4QpUA7NJl2t51uFu'),
array('name' => 'To Pimp a Butterfly', 'artist' => 'Kendrick Lamar', 'link' => 'https://open.spotify.com/album/7ycBtnsMtyVbbwTfJwRjSP'),
array('name' => 'Off the Wall', 'artist' => 'Michael Jackson', 'link' => 'https://open.spotify.com/album/2ZytN2cY4Zjrr9ukb2rqTP'),
array('name' => 'Vol. 3: The Subliminal Verses', 'artist' => 'Slipknot', 'link' => 'https://open.spotify.com/album/4ZDBQSIDIZRUBOG2OHcN3T'),
array('name' => 'Этажи', 'artist' => 'Molchat Doma', 'link' => 'https://open.spotify.com/album/1FHREwXgTQvqiG8q5KlRzc'),
array('name' => 'Hot Pink', 'artist' => 'Doja Cat', 'link' => 'https://open.spotify.com/album/1MmVkhiwTH0BkNOU3nw5d3'),
array('name' => 'Currents', 'artist' => 'Tame Impala', 'link' => 'https://open.spotify.com/album/79dL7FLiJFOO0EoehUHQBv'),
array('name' => 'INSIDE', 'artist' => 'Bo Burnham', 'link' => 'https://open.spotify.com/album/35qVMfUfBN6q2xzm9rZn5a'),
array('name' => 'Teenage Dream', 'artist' => 'Katy Perry', 'link' => 'https://open.spotify.com/album/2eQMC9nJE3f3hCNKlYYHL1'),
];
shuffle($albums);
$content = '';
foreach ($albums as $album) {
$content = $content . '
<tr>
<td><a href="' . $album['link'] . '" target="_blank">' . $album['name'] . '</a></td>
<td>' . $album['artist'] . '</td>
</tr>';
}
$html = '
<table>
<tr>
<th>Name</th>
<th>Artist</th>
</tr>
' . $content . '
</table>
';
return $html;
}
?>
+1
View File
@@ -0,0 +1 @@
+109
View File
@@ -0,0 +1,109 @@
<?php
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
$html = '';
$client_id = $_ENV['SPOTIFY_CLIENT_ID'];
$client_secret = $_ENV['SPOTIFY_CLIENT_SECRET'];
$access_token = get_access_token($client_id, $client_secret);
// TODO: Dynamically retrieve top 10 albums from Spotify API
// TODO: Implement server-side caching for faster load times.
$albums = [
'2FQieUp8BxPN7OR8fE76TE',
'5mUo2e4QpUA7NJl2t51uFu',
'7ycBtnsMtyVbbwTfJwRjSP',
'2ZytN2cY4Zjrr9ukb2rqTP',
'4ZDBQSIDIZRUBOG2OHcN3T',
'1FHREwXgTQvqiG8q5KlRzc',
'1MmVkhiwTH0BkNOU3nw5d3',
'79dL7FLiJFOO0EoehUHQBv',
'35qVMfUfBN6q2xzm9rZn5a',
'2eQMC9nJE3f3hCNKlYYHL1'
];
$content = '';
foreach ($albums as $album_id) {
$data = get_album($access_token, $album_id);
$content = $content . '<tr>
<td><img src="' . $data['images'][0]['url'] . '" /></td>
<td>' . $data['name'] . '</td>
<td>' . $data['artists'][0]['name'] . '</td>
<td><a href="' . $data['external_urls']['spotify'] . '" target="_blank">Spotify</a></td>
</tr>';
}
$html = '
<table>
<tr>
<th>Art</th>
<th>Name</th>
<th>Artist</th>
<th>Spotify</th>
</tr>' . $content . '</table>';
function get_access_token($client_id, $client_secret)
{
$url = 'https://accounts.spotify.com/api/token';
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $client_id,
'client_secret' => $client_secret
);
$post_data = http_build_query($data);
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
CURLOPT_POSTFIELDS => $post_data
));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
} else {
$data = json_decode($response, true);
curl_close($ch);
return $data['access_token'];
}
curl_close($ch);
}
function get_album($access_token, $album_id)
{
$url = 'https://api.spotify.com/v1/albums/' . $album_id;
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer $access_token"
)
));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
} else {
$data = json_decode($response, true);
return $data;
}
curl_close($ch);
}
echo $html;
?>
+14 -109
View File
@@ -1,119 +1,24 @@
<?php <?php
require_once 'vendor/autoload.php'; session_start();
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); include ('core.php');
$dotenv->safeLoad(); exec('php explore.php &');
$client_id = $_ENV['SPOTIFY_CLIENT_ID'];
$client_secret = $_ENV['SPOTIFY_CLIENT_SECRET'];
$access_token = get_access_token($client_id, $client_secret);
// TODO: Dynamically retrieve top 10 albums from Spotify API
$albums = [
'2FQieUp8BxPN7OR8fE76TE',
'5mUo2e4QpUA7NJl2t51uFu',
'7ycBtnsMtyVbbwTfJwRjSP',
'2ZytN2cY4Zjrr9ukb2rqTP',
'4ZDBQSIDIZRUBOG2OHcN3T',
'1FHREwXgTQvqiG8q5KlRzc',
'1MmVkhiwTH0BkNOU3nw5d3',
'79dL7FLiJFOO0EoehUHQBv',
'35qVMfUfBN6q2xzm9rZn5a',
'2eQMC9nJE3f3hCNKlYYHL1'
];
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Spotify Auth</title> <title>Favorite Albums</title>
<link rel="stylesheet" href="css/styles.css" type="text/css"> <link rel="stylesheet" href="css/styles.css" type="text/css">
<script src="js/switch.js"></script>
</head> </head>
<body> <body>
<h1>My Favorite Albums</h1> <h1>My Favorite Albums</h1>
<table> <button onclick=modeSwitch() type="submit">Click me</button>
<tr>
<th>Art</th> <div id="content">
<th>Name</th> <?php
<th>Artist</th> echo get_core();
<th>Spotify</th> ?>
</tr> </div>
<?php
foreach ($albums as $album_id) {
$data = get_album($access_token, $album_id);
echo '<tr>';
echo '<td><img src="' . $data['images'][0]['url'] . '" /></td>';
echo '<td>' . $data['name'] . '</td>';
echo '<td>' . $data['artists'][0]['name'] . '</td>';
echo '<td><a href="' . $data['external_urls']['spotify'] . '" target="_blank">Spotify</a></td>';
echo '</tr>';
}
?>
</table>
</body> </body>
</html> </html>
<?php
function get_access_token($client_id, $client_secret)
{
$url = 'https://accounts.spotify.com/api/token';
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $client_id, // Replace with your actual client ID
'client_secret' => $client_secret // Replace with your actual client secret
);
$post_data = http_build_query($data); // Build the URL-encoded string
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
CURLOPT_POSTFIELDS => $post_data
));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
} else {
$data = json_decode($response, true); // Decode into an associative array
curl_close($ch);
return $data['access_token'];
}
curl_close($ch);
}
function get_album($access_token, $album_id)
{
$url = 'https://api.spotify.com/v1/albums/' . $album_id;
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true, // Return the response as a string
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer $access_token" // Your Bearer token here
)
));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
} else {
$data = json_decode($response, true); // Decode into an associative array
return $data;
}
curl_close($ch);
}
?>
+10
View File
@@ -0,0 +1,10 @@
async function modeSwitch() {
const content = document.getElementById("content");
var response = await fetch('explore.php');
if (response.status === 200) {
let data = async () => { return await response.text() };
let text = await data();
content.innerHTML = text;
}
}
+3
View File
@@ -0,0 +1,3 @@
<?php
echo 'test';
?>
+3
View File
@@ -0,0 +1,3 @@
<?php
echo '<p>Test</p>';
?>