makandz/MySpotify

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:

image

This is what I want:

image

To Clarify, when I call the API in my code like:

image

I get the output:
image

Which is not what I want. What I want is the user's username.

If it's helpful, Here is the auth.php:

image

And here is the stats.php:

image

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:

  1. Clearing all the cookies to your localhost.
  2. Using incognito mode
  3. 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 👍

I tried eveything up to your second point which is the one that helped me identify the problem. The issue is that the cookie is not being set at all. Here is a screenshot of the EditThisCookie extension:

image

I would appreciate if you could help me fix this issue.

Many thanks,

Michael

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 🥴

Ah I see, can you try removing the two lines within the try catch exception?

image

These two specifically, see if it removes the cookie then as well?

I've removed these lines and tried again, I'm still recieving the "Guest" output and no cookie set.

I've added some error checking and I think I've found the faulty code:
image

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?