Spotify Webhooks?
Asked Answered
D

2

6

Does the Spotify platform plan to offer any webhooks for third party developers to listen in to changes in user libraries, playlists or the player?

What are some known workarounds if webhooks don't exist?

Dressingdown answered 25/7, 2018 at 23:1 Comment(1)
2020 and still no webhook support available from spotify. Really needed indeed.Joejoeann
C
8

There are no webhooks in the Web API and I think it will be quite a while before the feature is added https://github.com/spotify/web-api/issues/538

Playlists on Spotify are versioned by a snapshot_id. When you make an API request to get a playlist, one of the returned fields is snapshot_id, which identifies the playlist version. If you store this version ID for each playlist, you can check if the playlist has changed remotely since the last time you checked (the snapshot_id would change if so)

It's important to remember that any changes you make will also affect the snapshot_id. So you will need to:

  1. Get the Playlist
  2. Does your locally saved snapshot_id differ from the current one for the playlist?
  3. If it does, maybe make some changes
  4. After you make your changes, get the playlist again
  5. Store the snapshot_id from the Get Playlist after you made your changes

I don't think snapshot_id is supported for a user's library - you can check a subset of the user's library to detect any additions (e.g. if the first 50 songs in the library haven't changed, then no new songs have been added, and you only had to make one API request instead of umpteen), but you will miss deletions from the rest of the library if you only do this. You can also check the count of songs in the library, which would tell you when songs have been added or deleted, except in the edge case where they add and delete the same number of songs. But this means they have added a song and checking the first 50 songs in the library would catch this.

You can poll for currently playing and recently played songs. If you want to track every song a user listens to, you can achieve this by polling Recently Played at least every 30 * 50 seconds (25 mins). 30 is the number of seconds it takes to listen to a song before Spotify records it as a Listen and 50 is the max number of recently played songs it will serve you.

Chrisman answered 28/7, 2018 at 8:40 Comment(1)
would the Discord API provide options when you connect Spotify with Discord? support.spotify.com/us/article/discord-and-spotifyIndemnify
R
0

To know when a track finished playing I set an await function to wait for the duration of that track, and then continue after thet

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))

//start playing a track
    
let device_status = await spotifyApi.getMyCurrentPlaybackState().then(result =>{
      return result.body;
    })

 let time_left = device_status.item.duration_ms - device_status.progress_ms;
 await delay(time_left)

//whatever needs to be done after
Retrogressive answered 12/12, 2021 at 13:39 Comment(2)
What would happen if the user skipped or manually switched the song?Ragged
In my case, the play, pause and skip functions also work through the API, so I can reset the "timer" after any call. To catch changes in the player, I think there´s no ellegant way but another function to keep checking from time to time.Frap

© 2022 - 2024 — McMap. All rights reserved.