Using Spotify through Node Red

HI, longtime no reply. But I am trying to get this going in node-red. I do this:
image

And I have in the URI on spotify:

anything else I try is not workingā€¦ If I go to that URL I get:

And clicking on ā€œstart Authenticationā€ gives me:

Whats wrong? I have read everything on the forum and official site (https://flows.nodered.org/node/node-red-contrib-spotify) but seem to not find a solution.
Also not clear what these are for exactly: https://developer.spotify.com/documentation/general/guides/scopes/#streaming

same issue for me ā€¦

What I ultimately would like to achieve is this:

Since an alexa is coupled to 1 alexa account and all of them are connected to mine I can play Spotify easy to them. But my wife and kids canā€™t with the family spotify. They just donā€™t see the alexas. And this is a widely known ā€œerrorā€.

I thought of making some players in my profile I would be able to kick playing by node red when saying ā€œalexa turn on spot kidnameā€ (or something similar :sweat_smile:) and then play a list via my profile on alexaā€¦

maybee possible after correct integration in node red ? for the moment i donā€™t know how to configure it differently

No one can help?

i found that it seems to work :wink:

When you get this Invalid redirect URI page, copy the URL from that page
Open https://www.urldecoder.org/ and paste the URL in the top box and encode the URL
Copy the URL after the part ā€¦&redirect_uri= and before the next & (e.g. &state=)
Enter this URI in your spotify app in the redirect URI
For homeassistant users, it could look something like this:
http://homeassistant.local:8123/api/hassio_ingress/bla-bla/spotify-credentials/auth/callback

Hope this may help others as well.

Found the solution here:

5 Likes

appreciate the answer.

i have tried all I could but still no luck.

I see in your links it points to ā€œ8123ā€ port and not 1880 port. How is that correct if I use node red running on 1880?

What do you have in the "ā€œscopesā€ field in node-red? And what should happen when I click ā€œauthenticateā€ in node-red?

I get:
INVALID_CLIENT: Invalid client

update: remove the oauth and now working. I REALLY DONT KNOW WHAT IT WAS I DIDā€¦

spotify.authorized

Ok, now the next thing.

How to proceed now to use thisā€¦ :slight_smile:

you can find a flow example on google but for the moment i donā€™t use it ā€¦

Hi, I am further. Can play, pause, can next, skip etc. And I can do a ā€œtransferMyPlaybackā€ to another device (alexa) via the device id.

Only thing not wokring for me i how to find and how to select waht playlist to play thereā€¦

Like this:

What should I put in the function node and how do I get a playlist id?

This does not work:
msg.params = [ {playlistId: "37i9dQZF1DWXmlLSKkfdAk"} ]; return msg;
and a lot of others also not :slight_smile:
gives me:
{"_msgid":"2b1aaff.8d8e15","topic":"","payload":true,"params":[{"playlistId":"37i9dQZF1DWXmlLSKkfdAk"}],"error":"WebapiError: Bad Request"}

Iā€™m having trouble finding examples, or getting the function node to supply the correct information for just simple things like specifying a playlist too.

Would you mind posting how you managed to do play pause, etc. and transfer my playback, please?

Edit: OK, I found another post with more examples: Spotify node-red interface

You an get the deviceids by sending a string of ā€˜trueā€™ to get my devices, then looking at the debug console.

Then as above, use a function node with:

msg.params = [
    ['85202189a6blablsca22818c7383'],
    { play: true }
];
return msg;

@sender

msg.params = [ "3XubkIrRsDkykhyRsr8" ]; return msg;

in the function node for ā€˜getPlaylistā€™ returns my playlist in an array, but doesnā€™t play that playlist.

The same works for getPlaylistTracks

You can find the Spotifyid of the playlist by clicking on the 3 dots next to your playlist, then share, then copy spotify URI

Edit: Ok, you need to use play, rather than getPlaylist, and put this in the function node replacing your playlist uri

msg.params = [ {context_uri: "spotify:playlist:3XubktkkgujSVzMRsr8"} ]; return msg;

For setShuffle you need:

msg.params = [ "true" ]; return msg;

where true is to turn on shuffle. Thatā€™s probably enough edits for one post today. :slight_smile: Hope it helps.

Thing is the device ids randomly change now and then and I do not know whyā€¦

Thatā€™s alarming, and certainly puts a spanner in the works of automation. What sort of device is changing device ID? So far Iā€™ve only used my computer, and a bunch of Alexas, but they havenā€™t changed so farā€¦ touch wood, but then again Iā€™ve only just started using it.

The getmydevices node might be able to help with automation, but it will take someone with more nous than me to pass variables. Another option might be able to use Home Assistant itself, with Spotcastā€¦despite the name, it isnā€™t just a chromecast thing, but can broadcast to Alexas, computers, et cetera

For me only alexas changeā€¦ and no answer so farā€¦

Thanks for this. It solved my problems with invalid URI but now I have another issue. After agreeing to the permissions all I get is ā€œ401: Unauthorized.ā€ Anyone have an idea why?

My Spotify integration within HA is working without any issues, I just canā€™t seem to get this to work in Node Red.

@sender
hello friend please help me to make a flow to play a playlist on my google mini

What have you done yourself?

for the moment same problem impossible for me to play and send playlistā€¦ could you share your flow please?

I have it working, but one thing I found (maybe it has bin mentioned) is that you have to have an active connection to the chromecast or speaker, for instance through a phone or pc, only the you can use it, the player goes idl ones not connected and it will not work

do you have a flow to share?