"code" index not defined in callback.php?
amanuelanteneh opened this issue · 1 comments
I'm trying to follow the authorization code flow example from here
My auth.php is basically the same as the docs:
require 'vendor/autoload.php';
$session = new SpotifyWebAPI\Session(
'clientid',
'secret',
'http://localhost/callback.php/'
);
$state = $session->generateState();
$options = [
'scope' => [
'playlist-read-private',
'user-read-private',
],
'state' => $state,
];
header('Location: ' . $session->getAuthorizeUrl($options));
die();
And my callback.php is:
require 'vendor/autoload.php';
$session = new SpotifyWebAPI\Session(
'clientid',
'secret',
'http://localhost/callback.php/'
);
// Request a access token using the code from Spotify
$session->requestAccessToken($_GET['code']);
$accessToken = $session->getAccessToken();
$refreshToken = $session->getRefreshToken();
// Send the user along and fetch some data!
header('Location: index.php');
die();
But I keep getting this error: Undefined index: code in {projectPath}\callback.php on line 12.
I'm not sure why the code index seems to be null. I tried changing $_GET to $_REQUEST like another issue suggested but that yielded the same error.
If anyone else is having this issue, for some reason when I include the extra "/" at the end of my redirect URI this error occurs. However when I omit the "/" and instead use: http://localhost/callback.php as the redirect URI the issue resolves itself. Also make sure to omit the "/" when you whitelist the URI on your apps dashboard as well!