spotify-web-api-node
Version:
A Node.js wrapper for Spotify's Web API
31 lines (26 loc) • 1.02 kB
JavaScript
var SpotifyWebApi = require("../");
/**
* This example retrives an access token using the Client Credentials Flow. It's well documented here:
* https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow
*/
/*
* https://developer.spotify.com/spotify-web-api/using-scopes/
*/
/**
* Set the credentials given on Spotify's My Applications page.
* https://developer.spotify.com/my-applications
*/
var spotifyApi = new SpotifyWebApi({
clientId : 'fcecfc79122e4cd299473677a17cbd4d',
clientSecret : 'f6338737c9bb4bc9a71924cb2940eaedb'
});
// Retrieve an access token
spotifyApi.clientCredentialsGrant()
.then(function(data) {
console.log('The access token expires in ' + data['expires_in']);
console.log('The access token is ' + data['access_token']);
// Save the access token so that it's used in future calls
spotifyApi.setAccessToken(data['access_token']);
}, function(err) {
console.log('Something went wrong when retrieving an access token', err);
});