Spotify Web API播放端点 - 播放曲目

时间:2018-01-31 01:01:20

标签: spotify

我正在尝试使用Spotify Web API在传递曲目ID时播放曲目。我在Spotify的API控制台here上使用PUT https://api.spotify.com/v1/me/player/play端点。当我在PUT Body中使用示例数据,并添加我的设备ID和OAuth令牌abd时,单击“尝试”按钮,歌曲开始播放。当我将PUT Body更改为:

{
  "context_uri": "spotify:track:4ByEFOBuLXpCqvO1kw8Wdm"
}

我收到错误:

HTTP/1.1 400 Bad Request
Content-Length: 99
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, PATCH
Access-Control-Max-Age: 604800
Access-Control-Allow-Credentials: true
Content-Encoding: gzip
Keep-Alive: timeout=600
Server: nginx
Connection: keep-alive
Cache-Control: private, max-age=0
Date: Wed, 31 Jan 2018 00:56:54 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type, Retry-After
Content-Type: application/json; charset=utf-8

{
  "error" : {
    "status" : 400,
    "message" : "Non supported context uri"
  }
}

关于它为什么不起作用的任何想法?

2 个答案:

答案 0 :(得分:1)

如果您查看Spotify的API,track不支持context_uri

Optional. Spotify URI of the context to play.
Valid contexts are albums, artists & playlists.
Example: {context_uri:"spotify:album:1Je1IMUlBXcx1Fz0WE7oPT"}

https://developer.spotify.com/web-api/start-a-users-playback/

答案 1 :(得分:0)

如果你通过:

{
  "uris": ["spotify:track:4ByEFOBuLXpCqvO1kw8Wdm"]
}

它会起作用。您也可以,然后在uris列表中传递多首歌曲。