[GH-ISSUE #184] Authorization Code Flow's Error: Uncaught SpotifyWebAPI\SpotifyWebAPIAuthException: code must be supplied in #121

Closed
opened 2026-02-27 19:26:11 +03:00 by kerem · 1 comment
Owner

Originally created by @MarcelloDM on GitHub (Feb 20, 2020).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/184

I don't know if it can be useful for someone but after set my Authorization Code Flow I'm having this error:

PHP Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIAuthException: code must be supplied in {$INSTALL_PATH}\vendor\jwilsson\spotify-web-api-php\src\Request.php:54

Commenting the line header('Location: app.php'); in callback.php I noticed that the code variable was not gettable by the variabile $_GET['code'] . Infact it always was returned as NULL value and the $_GET as an empty array. So, in the callback.php, I changed the parameter of that call from:

$session->requestAccessToken($_GET['code'])

to that with the 'superglobal' $_REQUEST variable:

$session->requestAccessToken($_REQUEST['code'])

In this way, the code was being not NULL anymore and the access token was properly generated.
After that you can save $accessToken in a session variabile i.e. $_SESSION['accessToken'] = $accessToken; to make the access token visible to app.php.

Originally created by @MarcelloDM on GitHub (Feb 20, 2020). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/184 I don't know if it can be useful for someone but after set my **Authorization Code Flow** I'm having this error: `PHP Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIAuthException: code must be supplied in {$INSTALL_PATH}\vendor\jwilsson\spotify-web-api-php\src\Request.php:54 ` Commenting the line `header('Location: app.php');` in `callback.php` I noticed that the `code `variable was not gettable by the variabile `$_GET['code']` . Infact it always was returned as `NULL` value and the `$_GET` as an empty array. So, in the `callback.php`, I changed the parameter of that call from: `$session->requestAccessToken($_GET['code'])` to that with the 'superglobal' `$_REQUEST` variable: `$session->requestAccessToken($_REQUEST['code']) ` In this way, the code was being not NULL anymore and the access token was properly generated. After that you can save $accessToken in a session variabile i.e. `$_SESSION['accessToken'] = $accessToken;` to make the access token visible to app.php.
kerem closed this issue 2026-02-27 19:26:11 +03:00
Author
Owner

@jwilsson commented on GitHub (Feb 21, 2020):

Hey!
That's really strange that the $_GET array was empty. I'm glad you got it working with $_REQUEST though and shared it here.

I'm going to close this issue since it's not anything wrong with the library but thanks again for sharing it here!

<!-- gh-comment-id:589519106 --> @jwilsson commented on GitHub (Feb 21, 2020): Hey! That's really strange that the `$_GET` array was empty. I'm glad you got it working with `$_REQUEST` though and shared it here. I'm going to close this issue since it's not anything wrong with the library but thanks again for sharing it here!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#121
No description provided.