forslund / spotify-skill

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

Followed all directions and still "missing SPOTIPY_CLIEND_ID" #169

Closed colinbrogan closed 3 years ago

colinbrogan commented 3 years ago

I've followed all the directions, including walking through the auth.py credentials, and filling the questions in with the developer spotify account I created. Nonetheless, I get the following in skills.log:

2021-08-23 16:56:01.276 | ERROR | 842 | SpotifySkill | Couldn't fetch credentials Traceback (most recent call last): File "/opt/mycroft/skills/mycroft-spotify.forslund/init.py", line 271, in load_local_creds creds = load_local_credentials(self.settings['user']) File "/opt/mycroft/skills/mycroft-spotify.forslund/spotify.py", line 92, in load_local_credentials cache_path=token_cache) File "/opt/venvs/mycroft-core/lib/python3.7/site-packages/spotipy/oauth2.py", line 276, in init self.client_id = client_id File "/opt/venvs/mycroft-core/lib/python3.7/site-packages/spotipy/oauth2.py", line 92, in client_id self._client_id = _ensure_value(val, "client_id") File "/opt/venvs/mycroft-core/lib/python3.7/site-packages/spotipy/oauth2.py", line 71, in _ensure_value raise SpotifyOauthError(msg) spotipy.oauth2.SpotifyOauthError: No client_id. Pass it or set a SPOTIPY_CLIENT_ID environment variable.

It's as if I never entered the spotipy client id, but I did, multiple times, in auth.py. Is there somewhere else I need to put this?

forslund commented 3 years ago

Hi, what platform are you on? I assume you chose to save the credentials, I wonder if Mycroft is run on a different user than the one setting up the auth?

colinbrogan commented 3 years ago

Running a Mycroft Mark 1 with 21.2.0 software

colinbrogan commented 3 years ago

I saved the credentials in the skill settings, although there was no "connect" button in the skill settings to click (which the directions said to click). Also ran the auth script with all the dev account API stuff

colinbrogan commented 3 years ago

Also changed the user in the systemd service here: " [Unit] Description=Raspotify After=network.target

[Service] User=pi Group=pi Restart=always RestartSec=10 PermissionsStartOnly=true ExecStartPre=/bin/mkdir -m 0755 -p /var/cache/raspotify ; /bin/chown raspotify:raspotify /var/cache/raspotify Environment="DEVICE_NAME=raspotify (%H)" Environment="BITRATE=160" Environment="CACHE_ARGS=--disable-audio-cache" Environment="VOLUME_ARGS=--enable-volume-normalisation --volume-ctrl linear --initial-volume 100" Environment="BACKEND_ARGS=--backend alsa" Environment="DEVICE_TYPE=speaker" EnvironmentFile=-/etc/default/raspotify ExecStart=/usr/bin/librespot --name ${DEVICE_NAME} --device-type ${DEVICE_TYPE} $BACKEND_ARGS --bitrate ${BITRATE} $CACHE_ARGS $VOLUME_ARGS $OPTIONS

[Install] WantedBy=multi-user.target "

colinbrogan commented 3 years ago

Also activated the mycroft-core venv before running auth.py with this: source /opt/venvs/mycroft-core/bin/activate

forslund commented 3 years ago

On the Mark-1 Mycroft is run by a service user called mycroft. So it might be that you do this from the pi user and the config is saved in the incorrect user's config folder. I think you should do the following (if you haven't already):

sudo su mycroft
source /opt/venvs/mycroft-core/bin/activate
python /opt/mycroft/skills/mycroft-spotify.forslund/auth.py

Then to be certain, restart Mycroft

forslund commented 3 years ago

In the latest readme / settings page the "click connect" instructions has been removed (as far as I know). Where did you read those instructions?

colinbrogan commented 3 years ago

OK! running auth from the mycroft user surely fixed it! I've looked through the code on some of your skills, and thought about making some modifications and pushing them. Is there any specific reason you are doing this authentication from a python script, rather than having the user store these credentials in the skill's settings? I thought about rewriting your skill to make it easier for non-programmers, and perhaps pushing a merge request (if you find the code to be good).

forslund commented 3 years ago

This is a bit of a stop-gap solution. The oauth system was integrated with the Mycroft cloud in a "fairly" secure manner but Spotify shut down my client id for violation of their terms (using the API for voice interactions). So I knocked out this script so the the skill could still be used...

Possibly a hybrid solution could be done. You enter the credentials one time on the cloud when they're synced they can be removed from there.

I'm happy to accept a PR if you come up with a good solution.

amil109 commented 2 years ago

On the Mark-1 Mycroft is run by a service user called mycroft. So it might be that you do this from the pi user and the config is saved in the incorrect user's config folder. I think you should do the following (if you haven't already):

sudo su mycroft
source /opt/venvs/mycroft-core/bin/activate
python /opt/mycroft/skills/mycroft-spotify.forslund/auth.py

Then to be certain, restart Mycroft

Thank you for this - I had been trying for a long time to get the auth process to work - it was these 3 lines I needed. I don't know how many users are using a MK1 rather than a picroft or something else, but it might be worth adding these to the readme?

forslund commented 2 years ago

@amil109 yes, you are correct. it should be added to the readme. will handle that