Spotify tokens expire after one hour. You have to use a refresh token (obtained with your client id and client secret) to get a new access token.
This application allows you to get a refresh token through the authorization code flow.
You can then use this refresh token in batch scripts for example to obtain access tokens.
First you have to create an App by visiting the Spotify for Developers Dashboard. Note the client ID and the client Secret. On the Edit settings tab add this Redirect URIs : http://localhost:8888/callback
In the app.js file insert the client ID and the client Secret (lines 8 and 9).
In the app.js file insert the authorizations in the scope variable (line 29)
Run the following commands :
npm install
npm start
Open the URL http://localhost:8888/ in a browser.
By visiting the link Login with Spotify you are prompted to sign in to Spotify. Following this, the Redirect URI (http://localhost:8888/callback) is requested.
The server console displays the tokens and user informations.
By visiting the link Obtain a new token using the refresh token you get a new token with a validity of one hour.
The server console displays the tokens informations.