如何知道用户何时使用 Spotify 更改歌曲 API

How to know when the user changes the song with the Spotify API

我需要知道用户何时更改歌曲 "currently playing"。

目前,我正在使用 https://api.spotify.com/v1/me/player/currently-playing 获取有关 "currently playing" 歌曲的信息。但是,我需要知道它何时切换到下一首(不仅因为歌曲结束,还因为用户按下 NEXT SONG 按钮)。

我目前的解决方法是每秒调用 https://api.spotify.com/v1/me/player/currently-playing 端点,但如果我经常这样做,就会超出速率限制。

你做得对。您需要轮询 https://api.spotify.com/v1/me/player/currently-playing 端点以检测播放状态的变化。

在某些情况下,使用 Spotify's web playback SDK 是合适的,它会公开一个 player_state_changed 事件。为此,用户需要拥有高级帐户,并且播放需要在 SDK 创建的设备上进行。