Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Last active November 1, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillBrubaker/aab6bf4c80839cb85cdcead1e962578a to your computer and use it in GitHub Desktop.
Save WillBrubaker/aab6bf4c80839cb85cdcead1e962578a to your computer and use it in GitHub Desktop.
token refresher
//https://www.thathandsomebeardedguy.com/i'd-love-to-❤️-you-more
var credentials = {
clientId: 'someclientid',
clientSecret: 'someclientsecret',
redirectUri: 'http://localhost:8888/callback'
};
//npm install spotify-web-api-node --save
var SpotifyWebApi = require('spotify-web-api-node');
var spotifyApi = new SpotifyWebApi(credentials);
//npm install fs
var fs = require("fs");
var file = "token.txt";
var data = fs.readFileSync(file);
var token = data.toString().replace('\n','');
console.log(token);
spotifyApi.setAccessToken(token);
spotifyApi.setRefreshToken('A valid refresh token');
spotifyApi.refreshAccessToken().then(
function(data) {
fs.writeFile(file, data.body['access_token'], function(err){
if (err) {
//handle error
}
});
},
function(err) {
//handle error
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment