pckhib / node-red-contrib-spotify

Node-RED node for Spotify Web API
MIT License
13 stars 16 forks source link

transferMyPlayback not working #4

Open jackyohh opened 5 years ago

jackyohh commented 5 years ago

i use "inject" input to call a JSON payload. there i use the array {"device_ids":["1234567890"],"play":"true"} and call "transferMyPayback". Nothing happens. Play/Pause is working just fine and "getArtistAlbums" example is working too.
i even tried https://developer.spotify.com/console/put-user-player/?body={%22device_ids%22%3A[%221234567890%22]} and it is working just fine too.

in https://github.com/thelinmichael/spotify-web-api-node/blob/master/src/spotify-web-api.js i found "Transfer a User's Playback" but i have no clue how to use it in node-red-contrib-spotify.

jkwcht commented 4 years ago

For passing parameters to node-red-contrib-spotify it requires a 'params' field. Writing this into a function and connect it to the spotify-transferMyPlayback-node works for me: msg.params = [ {deviceIds: ["your-device-id"], play: 'true'} ]; return msg;

bigjobbyx commented 4 years ago

Please could you expand on this please. I have been trying for hours to get this node to work. Could you post your flow or maybe step by step it up?

I'm going bonkers trying to solve this

nicoausnrw commented 4 years ago

for other with the same issues. the answer from @jkwcht work well for me but a main problem is this spotify only knows devices where a app running, like my smartphone and PC. (In the time were the music play over my Chromecast, the is too in the device list.)

BUT if I play the music on my Phone and want switch to my chromecast, spotify don't know about the existence of the chromecast and shows a error. So right now I have no solution for this problem. Thing google must handle this. Here are later maybe more informations. klick

For all the need some more help to play on a divce this spotify knows, here a short step by step instruction.

  1. creat a flow: "inject with a TRUE" >> "node-red-contrib-spotify getMyDevices" >> "debug Payload"
  2. deploy
  3. push the inject Button, now you have in the debug sitebar a list about all divces, copy the ID of your device of choice
  4. now use the code snippet from @jkwcht with your device-ID
    • example flow: "inject with a TRUE" >> "function msg.params = [ {deviceIds: ["your-device-id"], play: 'true'} ]; return msg; " >> "node-red-contrib-spotify transferMyPayback"

EDIT: read the comments below, some have issues with my solution.

sawo69 commented 3 years ago

Did te steps according to @nicoausnrw but get the following error

{"_msgid":"3cc4b332.760afc","topic":"true","params":[{"deviceIds":["77c3c0a12cf8ef9ddca2dae79bdee811cc446f8d"],"play":"true"}],"err":"TypeError: Cannot read property 'play' of undefined"}

This is my node red

[{"id":"e2cf5f80.ea1c4","type":"inject","z":"1ec70ae1.ce8cc5","name":"True","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"msg","x":170,"y":240,"wires":[["c73c3743.869e68"]]}]

Tried to transfer the playback from my laptop to my main PC both have spotify

nicoausnrw commented 3 years ago

@sawo69

Here is my flow, maybe it will help you. You must edit the function after the import and set your Spotify auth.

[{"id":"9fcff8a1.e11c18","type":"debug","z":"469486cc.1f004","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1050,"y":60,"wires":[]},{"id":"6e3b8927.c4256","type":"spotify","z":"469486cc.1f004","name":"","auth":"HIDDEN FOR EXPORT","api":"transferMyPlayback","x":880,"y":60,"wires":[["9fcff8a1.e11c18"]]},{"id":"c3fde82d.b7bc38","type":"function","z":"469486cc.1f004","name":"Liste meiner Geräte","func":"\n\nmsg.params = [{\n deviceIds: [\"your-device-id\"], //not sure but maybe the id change sometime\n play: 'true'\n \n}]; \nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":60,"wires":[["6e3b8927.c4256"]]},{"id":"45085da9.3094f4","type":"inject","z":"469486cc.1f004","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":480,"y":60,"wires":[["c3fde82d.b7bc38"]]},{"id":"b66409c5.29f0e","type":"spotify-auth","z":0,"name":"Spotify OAuth2","scope":" playlist-read-private\n playlist-modify-private\n playlist-modify-public\n playlist-read-collaborative\n user-modify-playback-state\n user-read-currently-playing\n user-read-playback-state\n user-top-read\n user-read-recently-played\n app-remote-control\n streaming\n user-read-birthdate\n user-read-email\n user-read-private\n user-follow-read\n user-follow-modify\n user-library-modify\n user-library-read"}]

sawo69 commented 3 years ago

@nicoausnrw thanks for sharing your node red code. Unfortunately the error "TypeError: Cannot read property 'play' of undefined" persists also with your flow.

steve2211 commented 3 years ago

Same problem for me. Always getting the "TypeError: Cannot read property 'play' of undefined" error.

butabi commented 3 years ago

from the docs:

msg.params is used to define all required arguments for the specifed API call. It needs to be defined as an array. The order of the entries inside the array matches the order of the arguments for each function. For an overview about each API function check out the API description.

here is an example for transferMyPlayback (which has 2 arguments):

msg.params = [
    ['319827319827391823981732'], /* DeviceIds Array (but it can only handle one device id) */
    { play: true } /* Options Object */
];

hope this helps

sawo69 commented 3 years ago

from the docs:

msg.params is used to define all required arguments for the specifed API call. It needs to be defined as an array. The order of the entries inside the array matches the order of the arguments for each function. For an overview about each API function check out the API description.

here is an example for transferMyPlayback (which has 2 arguments):

msg.params = [
    ['319827319827391823981732'], /* DeviceIds Array (but it can only handle one device id) */
    { play: true } /* Options Object */
];

hope this helps

Thanks that helped. Now it is working. Don't understand the logic behind it but that is my lack of programming experience.