【问题标题】:Spotify API Add to playlistSpotify API 添加到播放列表
【发布时间】:2012-05-23 23:18:10
【问题描述】:

是否可以通过服务器端功能操作(添加到)Spotify 播放列表?

Web API 似乎仅限于搜索 (https://developer.spotify.com/technologies/web-api/),而具有该功能的 JavaScript API 参考似乎仅限于在 Spotify 本身内部构建应用程序......

【问题讨论】:

  • 您想代表用户操作播放列表,也就是 oauth 流程,还是只为您自己的用户操作?

标签: api spotify


【解决方案1】:

是的,你可以,但是你需要一个涉及用户的授权过程,这很痛苦。

您需要使用正确的 API。

来源: https://developer.spotify.com/web-api/console/playlists/

例如要添加曲目,您将需要此端点

https://api.spotify.com/v1/users/{user_id}/playlists/{playlist_id}/tracks

这段代码适用于 AppleScript,只是为了证明这个概念:

set userID to "XXXXX"
-- your userID can be retrieved with https://developer.spotify.com/web-api/console/get-current-user/#complete

set SelectedPlaylistID to "YYYY"
-- your target playlist can be retrieved with https://developer.spotify.com/web-api/console/get-playlists/#complete

set BearerID to "ZZZZ"
-- ZZZZ can be retrieved manually on page https://developer.spotify.com/web-api/console/post-playlist-tracks/ 

tell application "Spotify"
    set currentSpotifyID to id of current track as string
end tell
set currentlyPlayingTrack to trim_line(currentSpotifyID, "spotify:track:", 0)


set theURL to "'https://api.spotify.com/v1/users/" & userID & "/playlists/" & SelectedPlaylistID & "/tracks?uris=spotify%3Atrack%3A" & currentlyPlayingTrack & "' -H 'Accept: application/json' -H 'Authorization: Bearer " & BearerID & "'"
-- obtenu de https://developer.spotify.com/web-api/console/post-playlist-tracks/#complete

set theCommand to "curl -X POST " & theURL

do shell script theCommand

但是有一个很大的警告:您需要每小时刷新一次 BearerID。

哪里需要授权,如果想绕过刷新限制,哪里就复杂了。

【讨论】:

    【解决方案2】:

    不幸的是,如果不使用 JS API 在客户端内部构建 Spotify 应用程序或使用 libSpotify 构建独立应用程序,目前这是不可能的。

    【讨论】:

    • 你能通过服务器与 Spotify 应用程序对话吗?
    • libSpotify 如何与 Spotify 对话?它是与本地客户端还是远程服务器通信?
    • 它与远程服务器对话。
    猜你喜欢
    • 2012-12-20
    • 2012-01-21
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多