首页 > 解决方案 > 有没有办法使用 spotify 的 API 获取当前播放时间

问题描述

我正在制作一个网络应用程序,我将在其中嵌入我的 spotify 播客剧集。一旦播放了一定的秒数,我需要在我的网站上发生某些事情。有没有办法使用 API 获取播放时间?

标签: node.jsapiexpressspotify

解决方案


利用

/v1/me/player/currently-playing

返回progress_ms


例子:

要求

curl -X GET "https://api.spotify.com/v1/me/player/currently-playing" -H "Authorization: Bearer {your access token}"

回复

{
  "context": {
    "external_urls" : {
      "spotify" : "http://open.spotify.com/user/spotify/playlist/49znshcYJROspEqBoHg3Sv"
    },
    "href" : "https://api.spotify.com/v1/users/spotify/playlists/49znshcYJROspEqBoHg3Sv",
    "type" : "playlist",
    "uri" : "spotify:user:spotify:playlist:49znshcYJROspEqBoHg3Sv"
  },
  "timestamp": 1490252122574,
  "progress_ms": 44272, <------
  ...

另请注意,此 API 处于 Beta 阶段,如有更改,恕不另行通知。(或有功能或性能问题)

API 文档在此处此处


推荐阅读