Spotify 网络钩子? [英] Spotify Webhooks?
问题描述
Spotify 平台是否计划为第三方开发者提供任何网络钩子来监听用户库、播放列表或播放器的变化?
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?
如果 Webhook 不存在,有哪些已知的解决方法?
What are some known workarounds if webhooks don't exist?
推荐答案
Web API 中没有 webhooks,我认为添加该功能还需要很长时间 https://github.com/spotify/web-api/issues/538
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
Spotify 上的播放列表由 snapshot_id
进行版本控制.当您发出 API 请求以获取播放列表,返回的字段之一是 snapshot_id
,用于标识播放列表版本.如果您为每个播放列表存储此版本 ID,您可以远程检查自上次检查以来播放列表是否已更改(snapshot_id
会更改)
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)
请务必记住,您所做的任何更改也会影响 snapshot_id
.所以你需要:
It's important to remember that any changes you make will also affect the snapshot_id
. So you will need to:
- 获取播放列表
- 您本地保存的
snapshot_id
与播放列表中当前保存的snapshot_id
是否不同? - 如果是这样,也许会做出一些改变
- 进行更改后,再次获取播放列表
- 进行更改后,从获取播放列表"中存储
snapshot_id
- Get the Playlist
- Does your locally saved
snapshot_id
differ from the current one for the playlist? - If it does, maybe make some changes
- After you make your changes, get the playlist again
- Store the
snapshot_id
from the Get Playlist after you made your changes
我认为用户的库不支持 snapshot_id
- 您可以检查用户库的子集以检测任何添加(例如,如果前 50 首歌曲库中没有更改,然后没有添加新歌曲,您只需要发出一个 API 请求而不是无数次),但是如果您只这样做,您将错过库其余部分的删除.您还可以检查库中歌曲的数量,这会告诉您何时添加或删除了歌曲,除非它们添加和删除相同数量的歌曲.但这意味着他们添加了一首歌曲,检查库中的前 50 首歌曲就会发现这一点.
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.
您可以轮询当前播放和最近播放的歌曲.如果您想跟踪用户收听的每首歌曲,您可以通过至少每 30 * 50 秒(25 分钟)轮询一次最近播放来实现这一点.30 是在 Spotify 将歌曲录制为 Listen 之前听一首歌所需的秒数,50 是它将为您提供的最近播放歌曲的最大数量.
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.
这篇关于Spotify 网络钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!