API Not retrieveing data
Opened this issue · 7 comments
Hello, seems I've found another bug. I'm using your api and pretty much copied and pasted the code and what's happening is that the code is being set, but I'm still recieving the pre-defined $User data.
Getting this, even though cookie and code are set:
This is what I want:
To Clarify, when I call the API in my code like:
Which is not what I want. What I want is the user's username.
If it's helpful, Here is the auth.php:
And here is the stats.php:
Any help will be greatly appreciated!
Many thanks,
Michael
This could be many things, but the first thing I'd look at would be the setcookie
function. It could be that the cookie isn't properly being set/removed. A few things you can try:
0. Wipe all your cookies
A problem I have from time to time is that my cookies will refuse to reset. You can try:
- Clearing all the cookies to your localhost.
- Using incognito mode
- Try again with a different browser.
I'd also suggest downloading a fresh copy of mySpotify and trying it on an "fresh" browser (one with no cookies logged on it), see if that works. If all fails, follow the steps below.
1. Check if the cookie is being set at all
You can do this by removing the header() code from auth.php (to make sure it doesn't redirect you). Once Spotify redirects you to auth.php, you'll see a blank page. Open up some sort of cookie inspector (I personally use EditThisCookie on Chrome. You can check the cookies and see if the spotify_auth
cookie was set, and verify that it's actually set properly. (You can try var_dumping the code that was retrieved from auth.php and comparing it)
2. Check what's happening in stats.php
If the top works fine, you can redirect your page to index.php. If your client removes the cookie at this point, that means the authentication token is invalid. I've never experienced this issue so I'm not sure exactly what the solution is, so I'll need to look more into it 👍
After doing more testing, it seems that the cookie is being set inside auth.php but is instantly being unset in stats.php.
I might be wrong though 🥴
I've removed these lines and tried again, I'm still recieving the "Guest" output and no cookie set.
Sorry for the late response, got midterms coming up so I haven't had much time to check GitHub 😄
Could this be because the cookie isn't being set from the auth.php page?