-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.js
35 lines (27 loc) · 1004 Bytes
/
token.js
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
var SpotifyWebApi = require('spotify-web-api-node');
const fs = require('fs');
// Load and setup credentials
var rawsetup = fs.readFileSync('setup.json', 'utf8');
var setup = JSON.parse(rawsetup);
creds = {
clientId: setup.clientId,
clientSecret: setup.clientSecret,
redirectUri: setup.redirectUri
}
code = setup.code
// Initializes the api
var spotifyApi = new SpotifyWebApi(creds);
// Updates the access and refresh tokens in the setup.json file
spotifyApi.authorizationCodeGrant(code).then(
function(data) {
setup.access_token = data.body['access_token'];
setup.refresh_token = data.body['refresh_token'];
console.log('Access token:\n' + data.body['access_token']);
console.log('Expires in:\n' + data.body['expires_in']);
console.log('Refresh token:\n' + data.body['refresh_token']);
fs.writeFileSync("setup.json", JSON.stringify(setup), 'utf8');
},
function(err) {
console.log('Something went wrong!', err);
}
);