-
-
Save Uvacoder/a5d03db56b3ab2690441b972b3f25e7a to your computer and use it in GitHub Desktop.
token refresher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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