I'm trying to get a Spotify access token (with just a Client ID and Client Secret) using Node.js and Spotify Web API Node's Client Credential flow. Here is the code I have:
var SpotifyWebApi = require('spotify-web-api-node');
var spotifyApi = new SpotifyWebApi({
clientId : clientId, // my Client ID
clientSecret : clientSecret // my Client Secret
});
spotifyApi.clientCredentialsGrant()
.then(function(data) {
spotifyApi.setAccessToken(data.body['access_token']);
}, function(err) {
console.log('Something went wrong when retrieving an access token', err);
});
The problem I'm having is I always get the following error:
TypeError: spotifyApi.clientCredentialsGrant is not a function
I can access many other functions from this library with no problem. For instance, I can write:
console.log(`The Client secret is ${spotifyApi.getClientSecret()}`);
console.log(`The Client ID is ${spotifyApi.getClientId()}`);
And I get the expected output in the console:
The Client secret is [my Client Secret]
The Client ID is [my Client ID]
Interestingly, I can see many other available methods by using WebStorm's Code Completion. In fact, I can see 88 total methods (even more than are listed here), but clientCredentialsGrant()
is missing from that list as well.
I thought this would be fairly straightforward, but I must be making a simple mistake somewhere. Has anyone used this method successfully? Or has anyone encountered this error before? Is there a better way I should be doing this?