[GH-ISSUE #233] Unknown Error On Callback #168

Closed
opened 2026-02-27 19:26:24 +03:00 by kerem · 2 comments
Owner

Originally created by @amanuelanteneh on GitHub (Jun 15, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/233

I deployed an app using this library as a dependency to heroku and get this strange error message when trying to authenticate other users:

SpotifyWebAPI\SpotifyWebAPIException: An unknown error occurred. in /app/vendor/jwilsson/spotify-web-api-php/src/Request.php:59 Stack trace: #0 /app/vendor/jwilsson/spotify-web-api-php/src/Request.php(239): SpotifyWebAPI\Request->handleResponseError() #1 /app/vendor/jwilsson/spotify-web-api-php/src/Request.php(129): SpotifyWebAPI\Request->send() #2 /app/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api() #3 /app/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(1556): SpotifyWebAPI\SpotifyWebAPI->sendRequest() #4 /app/callback.php(32): SpotifyWebAPI\SpotifyWebAPI->me() #5 {main}

The error seems to occur when I call the me() function after setting the access token. My auth.php is:

require 'vendor/autoload.php';

$session = new SpotifyWebAPI\Session(
    'REMOVED',
    'REMOVED',
    'https://app.com/callback.php'
);


$options = [
    'scope' => [
        'playlist-read-private',
        'user-read-private',
        'user-top-read',
        'user-read-recently-played',
        'playlist-modify-public',
    ]
];

header('Location: ' . $session->getAuthorizeUrl($options));

die();

And my callback.php is:

require 'vendor/autoload.php';

$session = new SpotifyWebAPI\Session(
    'REMOVED',
    'REMOVED',
    'https://app.com/callback.php'
);

// Request a access token using the code from Spotify

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


$accessToken = $session->getAccessToken();
$refreshToken = $session->getRefreshToken();

setcookie('accessToken', $accessToken, time() + (86400 * 30));
setcookie('refreshToken', $refreshToken, time() + (86400 * 30));

try {
$api = new SpotifyWebAPI\SpotifyWebAPI();

$api->setAccessToken($_COOKIE['accessToken']);


setcookie("user", $api->me()->display_name, time() + (86400 * 10));

header('Location: https://spotify-stats-php.herokuapp.com/index.php');
die();
}
catch (SpotifyWebAPI\SpotifyWebAPIException $e) {
    echo $e;
}

I'm not sure what could be causing this as I followed the documentation on the authorization almost exactly. What's odd is that I can log in just fine but other users can't seem to and get this error.

Originally created by @amanuelanteneh on GitHub (Jun 15, 2021). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/233 I deployed an app using this library as a dependency to heroku and get this strange error message when trying to authenticate other users: SpotifyWebAPI\SpotifyWebAPIException: An unknown error occurred. in /app/vendor/jwilsson/spotify-web-api-php/src/Request.php:59 Stack trace: #0 /app/vendor/jwilsson/spotify-web-api-php/src/Request.php(239): SpotifyWebAPI\Request->handleResponseError() #1 /app/vendor/jwilsson/spotify-web-api-php/src/Request.php(129): SpotifyWebAPI\Request->send() #2 /app/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(124): SpotifyWebAPI\Request->api() #3 /app/vendor/jwilsson/spotify-web-api-php/src/SpotifyWebAPI.php(1556): SpotifyWebAPI\SpotifyWebAPI->sendRequest() #4 /app/callback.php(32): SpotifyWebAPI\SpotifyWebAPI->me() #5 {main} The error seems to occur when I call the me() function after setting the access token. My auth.php is: ``` require 'vendor/autoload.php'; $session = new SpotifyWebAPI\Session( 'REMOVED', 'REMOVED', 'https://app.com/callback.php' ); $options = [ 'scope' => [ 'playlist-read-private', 'user-read-private', 'user-top-read', 'user-read-recently-played', 'playlist-modify-public', ] ]; header('Location: ' . $session->getAuthorizeUrl($options)); die(); ``` And my callback.php is: ``` require 'vendor/autoload.php'; $session = new SpotifyWebAPI\Session( 'REMOVED', 'REMOVED', 'https://app.com/callback.php' ); // Request a access token using the code from Spotify $session->requestAccessToken($_GET['code']); $accessToken = $session->getAccessToken(); $refreshToken = $session->getRefreshToken(); setcookie('accessToken', $accessToken, time() + (86400 * 30)); setcookie('refreshToken', $refreshToken, time() + (86400 * 30)); try { $api = new SpotifyWebAPI\SpotifyWebAPI(); $api->setAccessToken($_COOKIE['accessToken']); setcookie("user", $api->me()->display_name, time() + (86400 * 10)); header('Location: https://spotify-stats-php.herokuapp.com/index.php'); die(); } catch (SpotifyWebAPI\SpotifyWebAPIException $e) { echo $e; } ``` I'm not sure what could be causing this as I followed the documentation on the authorization almost exactly. What's odd is that I can log in just fine but other users can't seem to and get this error.
kerem 2026-02-27 19:26:24 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jun 15, 2021):

Hey!
Have you created your app with Spotify recently? I think this might be related to the changes they recently made around app modes. I created a new app and a new Spotify account and got the same error. Unfortunately, Spotify doesn't seem to give any better errors back so it's not possible to show something other than the general "An unknown error occurred".

I think what you need to do is adding new users in your Developer dashboard or make a request for Extended Quota Mode (it's all outlined in their blog post).

Hope this solves the issue!

<!-- gh-comment-id:861175521 --> @jwilsson commented on GitHub (Jun 15, 2021): Hey! Have you created your app with Spotify recently? I think this might be related to [the changes](https://developer.spotify.com/community/news/2021/05/27/improving-the-developer-and-user-experience-for-third-party-apps/) they recently made around app modes. I created a new app and a new Spotify account and got the same error. Unfortunately, Spotify doesn't seem to give any better errors back so it's not possible to show something other than the general "An unknown error occurred". I think what you need to do is adding new users in your [Developer dashboard](https://developer.spotify.com/dashboard/) or make a request for Extended Quota Mode (it's all outlined in their blog post). Hope this solves the issue!
Author
Owner

@amanuelanteneh commented on GitHub (Jun 15, 2021):

That was the issue! For some reason my developer portal never updated with the new information. Thank you!

<!-- gh-comment-id:861534120 --> @amanuelanteneh commented on GitHub (Jun 15, 2021): That was the issue! For some reason my developer portal never updated with the new information. Thank you!
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#168
No description provided.