I ran into this, but found a fix. In Spotify, where you’ve created the app credentials, you have to add the callback URL to the whitelist. https://developer.spotify.com/my-applications
Once it’s on the whitelist, and you’ve saved, you should be able to authorize.
Finally got this working after going through this thread a few times. Thanks to all who shared!
Sorted out the base_url: setting in configuration.yaml and the Redirect URI in the Spotify developer settings, but when clicking on the setup link on the Home Assistant home page it would open a new tab with the URL that matched the whitelist url and what looked like the token after it.The home-assistant.log had the following,
2018-01-20 07:24:55 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 410, in start
resp = yield from self._request_handler(request)
File "/usr/lib/python3.6/site-packages/aiohttp/web.py", line 325, in _handle
resp = yield from handler(request)
File "/usr/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 93, in impl
return (yield from handler(request))
File "/usr/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 58, in ban_middleware
return (yield from handler(request))
File "/usr/lib/python3.6/asyncio/coroutines.py", line 213, in coro
res = yield from res
File "/usr/lib/python3.6/asyncio/coroutines.py", line 213, in coro
res = yield from res
File "/usr/lib/python3.6/site-packages/homeassistant/components/http/__init__.py", line 427, in handle
result = handler(request, **request.match_info)
File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/spotify.py", line 115, in get
self.oauth.get_access_token(request.query['code'])
File "/usr/lib/python3.6/site-packages/spotipy/oauth2.py", line 218, in get_access_token
raise SpotifyOauthError(response.reason)
Based on the SpotifyOauthError decided to double check the Spotify client_id and client_secret which were in secrets.yaml. The problem was that when pasting the client_secret I had gone one character too far and it had appended an underscore character to the end. Remeoved that, restarted HA and it authenticated first time.
I have read this whole thread about 5 times and im still having no luck
I think I have tried everything suggested, one thing is I have a non premium account does that matter ?
I use duckdns / hass.io, removed the duckdns plugin and adjusted my http: settings in my config.yaml, added the base url of my local IP address (base_url: “http://192.168.1.120:8123”)
When I go to HA I see the Spotify Configure button on my front end, and when I click that and click login I get the proper Spotify log in page for my Home Assistant app. It’s when I click login it just hangs on a page with URL https://xxxx.duckdns.org:8123/api/spotify?code=xxxxxxxxxxxxxx and says server not responding.
Any idea what I’m doing wrong? Could I manually use that “code” to create the Spotify config file myself now that Spotify said I am authorised in the app?
Change both the base_url under http in your config file and the spotify redirect url to your local ip. So base_url should be 192.168.0.x:8123 and the Spotify one should be https://192.168.0.x:8123/api/spotify … then change your base_url back to your duckdns one once you’ve got the media player showing
I’m on 0.82.0 and having the same struggles and I have tried all of the solutions suggested.
recap:
verified that in my configuration is correct (client, secret, and I have 4 redirect urls to account for:
https://[public]:[port]/api/spotify
https://[public]:[port]/api/spotify/
https://[local_ip]:[port]/api/spotify
https://[local_ip]:[port]/api/spotify/
I have tried with the http base_url as the following with no trailing slash
https://[public]:[port]
https://[local_ip]:[port]
Results:
The closets I can get is:
http base_url https://[public]:[port]
all 4 redirects in place from spotify side.
Click configure and get the “INVALID_CLIENT: Invalid redirect URI” error from the spotify side.
I change that redirect url from #4 in the browser to the IP
Which then get me the :
File “/usr/local/lib/python3.6/site-packages/spotipy/oauth2.py”, line 218, in get_access_token
raise SpotifyOauthError(response.reason)
spotipy.oauth2.SpotifyOauthError: Bad Request
Finally: I did try using http:/[ip]/api/spotify meaning no SSL but I don’t know how to turn off all of my security to get this to be accepted. To be honest I don’t know that I really want to.
Update: My issue was all user error. I left out the !secret when including my password and the validation check thus didn’t catch it b/c it thought the variable was my password. So having my base_url be https://[internal IP] worked!
I did have the same issue. Finally I tried to add the uri part of the url which was shown when I got the error message. In my case it was http://192.168.x.xxx:8123/lovelace/1.
I have no base_url set. Look at the URL the where you are displaying the Spotify card. Mine was http://hassio.local:8123/lovelace/0 (or your ip/url. I trued lovelace/1 and it didn’t work, then I noticed my page was at lovelace/0 and I changed it in the Spotify app uri then BAM! It works on my LAN and via HTTPS externally with a lets encrypt cert.
I must have been completely confused by the posters using the url with /lovelace/0 in it. I’ve got Spotify working, and don’t see an error message page.
Was trying to setup the Last.FM integration at the same time and one needs an url there also, which I didnt get.
Sorry for the mixup.
btw, Ive configured the dev-api without a url, and it works alright