Spotify WebApi for Node.js
- refresh accessToken with help refreshToken
- get user profile
- get user playlists
- following users/artists
- get
- add (follow)
- delete (unfollow)
- contains
- following playlist
- add (follow)
- delete (unfollow)
- contains
var SpotifyModule = require('spotify-middleware-webapi');
var spotifyModule = new SpotifyModule({
"credentials": {
"clientId": "[clientId]",
"clientSecret": "[clientSecret]",
"redirect_uri": "http://localhost:3000/auth/callback"
}
});
You can use passport-spotify for auth and receive accessToken and refreshToken.
var refreshToken = [your refresh token];
spotifyModule.tokenRefresh(refreshToken, function(err, accessToken) {
//...
});
accessToken is required. refreshToken - optional. Only for update accessToken.
spotifyModule.user({
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, profile, accessToken) {
// updated accessToken
});
or
spotifyModule.user({
accessToken: accessToken
}, function(err, profile, accessToken) {
// updated accessToken
});
spotifyModule.user(accessToken, function(err, profile, accessToken) {
// updated accessToken
});
var q = 'search_string';
var opts = {
limit: 20,
offset: 0,
market: 'US',
type: ['album', 'artist', 'track', 'playlist']
};
spotifyModule.search(q, opts, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.user({
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, profile, accessToken) {
//...
});
spotifyModule.playlists({
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.playlists(userId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.playlist(ownerId, userId, opts, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.user({
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.user.add(followingId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.user.delete(followingId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.user.contains(followingId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.playlist.add(playlistOwnerId, playlistId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.playlist.delete(playlistOwnerId, playlistId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});
spotifyModule.following.playlist.contains(playlistOwnerId, playlistId, userId, {
accessToken: accessToken,
refreshToken: refreshToken
}, function(err, results, accessToken) {
//...
});