[GH-ISSUE #244] Error 403 (Forbidden)!! on requestAccessToken() #175

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

Originally created by @moonswim on GitHub (Jan 7, 2022).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/244

Hello there!!

Im running into an issue which wasn't a problem before...

The code keeps getting stuck in.

In the Request.php the function handleResponseError()
// Something else went wrong, try to give at least some info
throw new SpotifyWebAPIException($body, $status);

I have dd()-d and checked if im passing everything correctly and it seems like i do.

In my controller keeps pointing to this line of error:

$session->requestAccessToken($code);

where before it i have:

$spotifyAccount = SpotifyAccount::where('id', 1)->first();

$session = new SpotifyWebAPI\Session(
$spotifyAccount->client_id,
$spotifyAccount->client_secret,
$spotifyAccount->redirect_uri
);

$code = $_GET['code'];

i have everything correct as the client_id, client_secret and redirect_uri.

Checking the function of requestAccessToken i realized that you don't pass any header to it which on the Spotify Web Api guides said you must include these:

HEADER PARAMETER | VALUE
Authorization | RequiredBase 64 encoded string that contains the client ID and client secret key. The field must have the
format: Authorization: Basic

Content-Type | RequiredSet to application/x-www-form-urlencoded.

But after adding the missing header i get the same error, which is an Error 403 (Forbidden)!!...

Please could you give me any tip on what im a not seeing :(

Originally created by @moonswim on GitHub (Jan 7, 2022). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/244 Hello there!! Im running into an issue which wasn't a problem before... The code keeps getting stuck in. In the Request.php the function handleResponseError() // Something else went wrong, try to give at least some info throw new SpotifyWebAPIException($body, $status); I have dd()-d and checked if im passing everything correctly and it seems like i do. In my controller keeps pointing to this line of error: $session->requestAccessToken($code); where before it i have: $spotifyAccount = SpotifyAccount::where('id', 1)->first(); $session = new SpotifyWebAPI\Session( $spotifyAccount->client_id, $spotifyAccount->client_secret, $spotifyAccount->redirect_uri ); $code = $_GET['code']; i have everything correct as the client_id, client_secret and redirect_uri. Checking the function of requestAccessToken i realized that you don't pass any header to it which on the Spotify Web Api guides said you must include these: HEADER PARAMETER | VALUE Authorization | RequiredBase 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret> Content-Type | RequiredSet to application/x-www-form-urlencoded. But after adding the missing header i get the same error, which is an Error 403 (Forbidden)!!... Please could you give me any tip on what im a not seeing :(
kerem 2026-02-27 19:26:27 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jan 8, 2022):

Hey!
This sounds strange. Are you getting any more info than just 403? Is the message just "Forbidden" or are you getting something more?

It's a bit strange that Spotify's docs no longer mentions the access token request method used by this library (that code has looked the same for years and everything is working when I try it locally). I did make some updates to follow their new docs and please test it out (it's located in a new branch which you can install with composer require jwilsson/spotify-web-api-php:dev-session-refactor).

<!-- gh-comment-id:1008071006 --> @jwilsson commented on GitHub (Jan 8, 2022): Hey! This sounds strange. Are you getting any more info than just 403? Is the message just "Forbidden" or are you getting something more? It's a bit strange that Spotify's docs no longer mentions the access token request method used by this library (that code has looked the same for years and everything is working when I try it locally). I did make some updates to follow their new docs and please test it out (it's located in [a new branch](https://github.com/jwilsson/spotify-web-api-php/tree/session-refactor) which you can install with `composer require jwilsson/spotify-web-api-php:dev-session-refactor`).
Author
Owner

@moonswim commented on GitHub (Jan 9, 2022):

Hello there first of all thank you for the fast reply!!
I did update the package from the branch you mentioned but it keeps doing the same...

Screenshot 2022-01-09 at 19 44 32 Screenshot 2022-01-09 at 19 44 43 Screenshot 2022-01-09 at 19 44 54
<!-- gh-comment-id:1008361985 --> @moonswim commented on GitHub (Jan 9, 2022): Hello there first of all thank you for the fast reply!! I did update the package from the branch you mentioned but it keeps doing the same... <img width="982" alt="Screenshot 2022-01-09 at 19 44 32" src="https://user-images.githubusercontent.com/82272113/148698112-edf82832-8809-4aaf-9d2e-6a473cb90ccf.png"> <img width="1007" alt="Screenshot 2022-01-09 at 19 44 43" src="https://user-images.githubusercontent.com/82272113/148698115-52225aee-1c8a-46f4-ac19-54238e6204c3.png"> <img width="1083" alt="Screenshot 2022-01-09 at 19 44 54" src="https://user-images.githubusercontent.com/82272113/148698116-fd83f510-0a45-40e2-ba52-b0955344d4c3.png">
Author
Owner

@jwilsson commented on GitHub (Jan 10, 2022):

That looks like an error from Google, very strange. It doesn't look like it's even making its way to Spotify but some Google URL instead. Where are you hosting it? Google Cloud? Have you tried running it locally and see if it works there?

<!-- gh-comment-id:1009249302 --> @jwilsson commented on GitHub (Jan 10, 2022): That looks like an error from Google, very strange. It doesn't look like it's even making its way to Spotify but some Google URL instead. Where are you hosting it? Google Cloud? Have you tried running it locally and see if it works there?
Author
Owner

@moonswim commented on GitHub (Jan 10, 2022):

Its being hosted on Linode, since December 8 or 9 i'm having this issue, before that it was working fine.
I can get up to here:
Screenshot 2022-01-10 at 19 39 37

Okey, i was about to rewrite my message because i just tried it like i did for the past month and now it worked...
Yesterday i was doing the php artisan config:clear and php artisan cache:clear after the integration of your new branch but it did not work now i have no clue why it did....

I did not change anything, same computer, same terminal, same code its weird and worrying because something seems unstable and i don't know what :(

Thank you very much again for the response your library is awesome and it helped me to save a ton of time, up until now i didn't experience any problem with it.

Thanks again and you are awesome!

Cheers!

<!-- gh-comment-id:1009286473 --> @moonswim commented on GitHub (Jan 10, 2022): Its being hosted on Linode, since December 8 or 9 i'm having this issue, before that it was working fine. I can get up to here: <img width="1136" alt="Screenshot 2022-01-10 at 19 39 37" src="https://user-images.githubusercontent.com/82272113/148828496-1ccc4247-2f99-4489-b38f-6c67ac48e7c7.png"> Okey, i was about to rewrite my message because i just tried it like i did for the past month and now it worked... Yesterday i was doing the php artisan config:clear and php artisan cache:clear after the integration of your new branch but it did not work now i have no clue why it did.... I did not change anything, same computer, same terminal, same code its weird and worrying because something seems unstable and i don't know what :( Thank you very much again for the response your library is awesome and it helped me to save a ton of time, up until now i didn't experience any problem with it. Thanks again and you are awesome! Cheers!
Author
Owner

@jwilsson commented on GitHub (Jan 11, 2022):

Just so I'm following 😅 everything's working now? If so, awesome! Let's hope it keeps working then!

<!-- gh-comment-id:1010133203 --> @jwilsson commented on GitHub (Jan 11, 2022): Just so I'm following 😅 everything's working now? If so, awesome! Let's hope it keeps working then!
Author
Owner

@moonswim commented on GitHub (Jan 11, 2022):

Yes it is currently working, and the refreshAccessToken is fine, when the expiration time is over it gets the new one so i don't know what happened or why but for now i close this issue.

Thank you!

<!-- gh-comment-id:1010189923 --> @moonswim commented on GitHub (Jan 11, 2022): Yes it is currently working, and the refreshAccessToken is fine, when the expiration time is over it gets the new one so i don't know what happened or why but for now i close this issue. 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#175
No description provided.