dupontgu / retro-ipod-spotify-client

The software that powers the sPot: a 4th generation "Click Wheel" iPod with a full Spotify client.
Apache License 2.0
893 stars 90 forks source link

Cannot access `.cache` file #7

Open wanbinkimoon opened 3 years ago

wanbinkimoon commented 3 years ago

I have setup env vars but still getting this error

❯ python3 spotifypod.py
Couldn't read cache at: .cache
Couldn't read cache at: .cache
Enter the URL you were redirected to: http://google.com
Enter the URL you were redirected to: no ints
Couldn't read cache at: .cache
mattkerrison commented 3 years ago

+1 have the same issue

utkut commented 3 years ago

Hey y'all,

The reason why you get that error is because there is no .cache file created yet. And you are setting the application for the first time.

After getting the Spotify API recall url set to http://127.0.0.1, and entering this website below:

https://accounts.spotify.com/authorize?client_id=XXXXXXXXXXXXXXXXXXXXXXXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative%20user-library-modify%20user-library-read%20streaming (replace x with client_id)

Once you sign in with your Spotify Credentials, it will forward you to a link with 127.0.0.1/?........ when u paste that link to the console, you should be able to launch the application.

I have been preparing a detailed instructions based on the project information. Let me know if there's something missing.

dupontgu commented 3 years ago

Hey all - I wish I could give better instructions, but I don't have bandwidth at the moment. What I would do (and what I did initially) is follow spotipy's quick start guide for setting up the "client credentials flow" in a separate application. Once you get authenticated, the .cache file will be generated. Then you can just copy it into this project.

dupontgu commented 3 years ago

Thank you @utkut I appreciate all the help.

utkut commented 3 years ago

@dupontgu No worries, it might be a good idea to write a documentation regarding the needed scopes as well. I went a bit overkill with getting full permission from the user.

mattkerrison commented 3 years ago

@utkut I managed to get the url call back in my browser http://127.0.0.1/?code=XXXXXXXX What console do you mean to paste it into? do you just create a .cache file in the directory and paste the code?

utkut commented 3 years ago

@mattkerrison When you are executing the python file for the first time, it asks you "Enter the URL you were redirected to:" and you paste the callback url to that prompt and then it generates the cache with your key.

mattkerrison commented 3 years ago

Ahh, mine doesn't even get that far, just sitting at: Couldn't read cache at: .cache Couldn't read cache at: .cache

will keep debugging, thanks!

nsier commented 3 years ago

Apologies for the rookie question, but Im having trouble finding the .cache file that the Client Connect Flow sample app created. Any insight on where to find it and where to copy it so it can be used by spodifypod would be super appreciated.

utkut commented 3 years ago

@nsier The cache file is created afterwards the you paste the redirect url. The cache file contains the credentials, so unless you get authenticated with the Spotify API, there will be no cache file in your directory.

nsier commented 3 years ago

@nsier The cache file is created afterwards the you paste the redirect url. The cache file contains the credentials, so unless you get authenticated with the Spotify API, there will be no cache file in your directory.

I hate to bother with such silly questions, Im not much of a programmer, but with headless Raspberry OS, how do I tell what what URL that a browser is redirected to?

rsappia commented 3 years ago

@nsier just use this one: https://accounts.spotify.com/authorize?client_id=XXXXXXXXXXXXXXXXXXXXXXXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative%20user-library-modify%20user-library-read%20streaming (replace x with client_id)

and the address you get (starting with 127.0.0....) is the one you paste in your console ;)

nsier commented 3 years ago

@nsier just use this one: https://accounts.spotify.com/authorize?client_id=XXXXXXXXXXXXXXXXXXXXXXXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative%20user-library-modify%20user-library-read%20streaming (replace x with client_id)

and the address you get (starting with 127.0.0....) is the one you paste in your console ;)

Im getting an INVALID_CLIENT: Invalid redirect URI

thanks

rsappia commented 3 years ago

@nsier u are welcome.You should read here:

https://spotipy.readthedocs.io/en/2.16.1/#client-credentials-flow

Set the environment variables using :

export SPOTIPY_CLIENT_ID='your-spotify-client-id' export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret' export SPOTIPY_REDIRECT_URI='your-app-redi

nsier commented 3 years ago

@rsappia many thanks for your help here. You're guidance helped me solve this issue!

doctorleach commented 3 years ago

I also was having two nights of trouble getting the .cache file. In my case the solution turned out to be simple--install a browser on the Pi Zero. I don't believe this step was mentioned in the guides. From past experience I thought Midori might be a good lightweight browser to install but it took some time because of the many dependencies. Also, it really taxes the Pi Zero, so to speed thing up a lot, I popped the SD card from the Zero into a Pi 4 and Midori ran at an acceptable speed. It was called automatically when I tried to run the spotifypod.py script and I had to log into spotify to approve the authorization. This only needs to be done once (unless you somehow erase the .cache file). I don't think the browser gets called again, which is fortunate given how many resources it takes up.

If you get an "address already in use" error, just reboot the Pi. Also, as mentioned above the environment variables need to be set, particularly paying attention that the SPOTIPY_REDIRECT_URI matches the redirect URI you entered into your project in developer.spotify.com exactly.

Finally, at least one of the following commands needs to be uncommented--i.e., active--in spotifypod.py (the second calls the first, so no need for both):

spotify_manager.refresh_devices() spotify_manager.refresh_data()