jwilsson / spotify-web-api-php

A PHP wrapper for Spotify's Web API.
MIT License
862 stars 156 forks source link

Error 403 (Forbidden)!! on requestAccessToken() #244

Closed moonswim closed 2 years ago

moonswim commented 2 years ago

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 :(

jwilsson commented 2 years ago

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).

moonswim commented 2 years ago

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
jwilsson commented 2 years ago

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?

moonswim commented 2 years ago

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!

jwilsson commented 2 years ago

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

moonswim commented 2 years ago

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!