Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spotify Webhooks?

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?

like image 426
Jeffrey Avatar asked Jul 25 '18 23:07

Jeffrey


People also ask

Does Spotify have Webhooks?

Spotify + Webhooks by Zapier Integrations Zapier lets you send info between Spotify and Webhooks by Zapier automatically—no code required. Triggers when you create a new playlist.

How webhooks work?

Webhooks are automated messages sent from apps when something happens. They have a message—or payload—and are sent to a unique URL—essentially the app's phone number or address. Webhooks are almost always faster than polling, and require less work on your end. They're much like SMS notifications.


1 Answers

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.

like image 55
Rach Sharp Avatar answered Oct 14 '22 03:10

Rach Sharp