forslund / spotify-skill

Mycroft Skill to control spotify using the Spotify Connect API
Apache License 2.0
71 stars 38 forks source link

Local api key #162

Closed forslund closed 3 years ago

forslund commented 3 years ago

Add support for using personal developer keys.

This adds a simple auth script to help create local credentials and store them in a specific path for usage by the skill. It also offers to save the client_id and client_secret for convenience (but will work with passing those as environment variables as well)

fermulator commented 3 years ago

Test Results:

(.venv) pi@picroft:/opt/mycroft/skills/mycroft-spotify.forslund $ git status
On branch 20.08

(.venv) pi@picroft:/opt/mycroft/skills/mycroft-spotify.forslund $ git checkout origin/feature/local-api-key2
Note: checking out 'origin/feature/local-api-key2'.
  1. Read the readme :)
  2. Got my spotify access token
  3. Stumbled through to get my spotify application created (see feedback on readme)
  4. Entered client ID, client secret, and username, got the redirect URI https://accounts.spotify.com/authorize?client_id=SNIP_CLIENT_ID&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A8888&scope=playlist-read-private+streaming+user-library-read+user-read-playback-state+user-top-read
  5. but: hitting that, says: INVALID_CLIENT: Invalid redirect URI
  6. AH, i didn't do the redirect URI whitelist trick in the spotify app settings; (EDIT, settings)
  7. spotipy doesn't QUITE state it, but we need to ACCEPT TERMS first, then it tries to redirect to the localhost:8888 URL,
  8. plop that in:
    
    Enter the URL you were redirected to: https://localhost:8888/?code=(SNIP)

Traceback (most recent call last): File "skills/mycroft-spotify.forslund/auth.py", line 46, in sp = spotipy.Spotify(auth_manager=am) TypeError: init() got an unexpected keyword argument 'auth_manager' (.venv) pi@picroft:~/mycroft-core $



UPDATE NEXT ROUND: per discussion with @forslund 
9. The above stack trace is because `requirements.txt` on the feature branch won't get auto-updated necessarily by `msm`; so to test we had to manually do: `mycroft-pip install -r skills/mycroft-spotify.forslund/requirements.txt`
10. Re-ran the script, but this time I didn't get prompted for the redirect URL hmmm (since the spotipy version upgrade?...)
11. Had to manually do it (luckily i had the ABOVE link ... @forslund msg'd about this)
12. FINAL TESTS = WORKING!
forslund commented 3 years ago

Gonna merge this in the current state since A it seems to work (for me atleast) and B we need something to base future work on and receive more bugreports :)

forslund commented 3 years ago

I'm going to merge this branch in the state it is now. and we can open new issues and PR's for specific fixes as they are needed.