Spotify Config

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.

3 Likes

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.

Hope this can help someone.

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”)

I also added my ip in the redirect of the spotify developer page - http://192.168.1.120:8123/api/spotify

I also tried this with duckdns using my https url etc etc…

so confused…

EDIT

OK well now i feel like a right dickhead !

So my issue was with the component, I left the < and > from the home assistant website in for my client no. and secret removed

working now…

1 Like

Hi all, is anyone planning to update the documentation based on what’s been learned in this thread?

I’m stuck…

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?

Thanks :smiley:

I follows from this and works perfect. I didn’t use any aliases: from the config

1 Like

Thanks! It just hangs for me when I try to load the https://xxxx.duckdns.org:8123/api/spotify link… if you try to go to just https://xxxx.duckdns.org:8123 does anything load? For me that also give a “page took too long to respond” and I’m not sure if it should?

This worked for me.

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

1 Like

it works! thanks you @teachingbirds

The “S” in spotify should not be capitalized. Could cause this issue (since I don’t know how HA does its internal URI resolution)

If you guy still have issues getting Spotify working (INVALID_CLIENT: Invalid redirect URI) …

I have Hass.io 0.77.3 running on HassOS 1.10, Hass.io supervisor 136.

I logged in to https://developer.spotify.com/dashboard/applications/ and edited the application’s settings.
I added http://192.168.x.xx:8123/api/spotify as one of the “Redirect URIs” and went back to HA and tried again.

Voilà, it now works.

Hope it helps!
/Fernando

1 Like

struggled with problem but yes following this it worked!

I’m on 0.82.0 and having the same struggles and I have tried all of the solutions suggested.

recap:

  1. 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/

  2. 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:

  1. http base_url https://[public]:[port]
  2. all 4 redirects in place from spotify side.
  3. Click configure and get the “INVALID_CLIENT: Invalid redirect URI” error from the spotify side.
  4. I change that redirect url from #4 in the browser to the IP
  5. 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!

Thanks,

Anyone has a final answer to this problem with the redirect URI and the invalid client error message?

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.

This worked! :slight_smile:

1 Like

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.

EDIT…

i got this now: INVALID_CLIENT: Invalid redirect URI

I just figured it out. You need to add each FULL URL to the spotify URL call-back list like @nelbs mentioned.

what exactly do you mean by that? what is the full url? of which page do we need to use the url…

The URL that Spotify is sending you to. It will be in the URL of your error message page.

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 :wink: