Spotify App API - Playlist Subscribe

2019-04-02 14:07发布

问题:

Looking at the APP API, it seems like you can determine whether or not a user is subscribed to a playlist or not. However, my app requires the user to be able to subscribe or un-subscribe from a playlist.

Is this possible using the Javascript App API at all?

回答1:

For the currently logged in user you can subscribe and unsubscribe from a playlist by setting the playlist's subscribed property.

var m = sp.require('sp://import/scripts/api/models')
var playlist = m.Playlist.fromURI('spotify:user:<otherUser>:playlist:<playlist>')

playlist.subscribed

> false

playlist.subscribed = true
playlist.subscribed

> true

playlist.subscribed = false
playlist.subscribed

> false