Open Gemiou opened 6 years ago
Sorry if I'm misunderstanding your question, but the following code should let you reset and save your access token so you can continue making calls:
// clientId, clientSecret and refreshToken has been set on the api object previous to this call.
spotifyApi.refreshAccessToken().then(
function(data) {
console.log("The access token has been refreshed!");
// Save the access token so that it's used in future calls
spotifyApi.setAccessToken(data.body["access_token"]);
},
function(err) {
console.log("Could not refresh access token", err);
}
);
Hello to retrieve an access token ,I call the function getToken after 3600.
getoken();
// Retrieve an access token.
function getoken() {
// 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']);
spotifyApi.setAccessToken(data.body['access_token']);
},
function (err) {
console.log('Something went wrong when retrieving an access token', err);
}
);
}
setInterval(getoken, 1000 * 60 * 60);
Hi,
instead of clientCredentialsGrant
you might want to consider using authorizationCodeGrant
- the client credentials authorization flow does not support refreshing of the access token - see: https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-flows
I have setup correct my Client Credential flow and i can get my token to make my calls but after 3600 i want to get new (My app use only "public" spotify endpoints) Sorry for my english.