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?
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?
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:
snapshot_id
differ from the current one for the playlist?snapshot_id
from the Get Playlist after you made your changesI 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.
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
© 2022 - 2024 — McMap. All rights reserved.