forked from thelinmichael/spotify-web-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess-token-using-client-credentials.js
More file actions
36 lines (31 loc) · 1.01 KB
/
access-token-using-client-credentials.js
File metadata and controls
36 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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: '<insert client id>',
clientSecret: '<insert client secret>'
});
// Retrieve an access token
spotifyApi.clientCredentialsGrant().then(
function(data) {
console.log('The access token expires in ' + data.body['expires_in']);
console.log('The access token is ' + data.body['access_token']);
// Save the access token so that it's used in future calls
spotifyApi.setAccessToken(data.body['access_token']);
},
function(err) {
console.log(
'Something went wrong when retrieving an access token',
err.message
);
}
);