Access Token not working
See original GitHub issueHi,
My access tokens do not seem to be set correctly. My code is taken from the example (and I have relplaced my id & secret):
var SpotifyWebApi = require('spotify-web-api-node');
var clientId = 'myclientid',
clientSecret = 'myclientsecret';
var spotifyApi = new SpotifyWebApi({
clientId : clientId,
clientSecret : clientSecret
});
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);
});
I receive the access token and expiration time, but then if I attempt to search for songs/artists/related artists/anything else, I also receive: { [WebapiError: Unauthorized] name: 'WebapiError', message: 'Unauthorized', statusCode: 401 }
even though the setAccessToken has been completed.
Furthermore, unlike the other closed issues similar to this, the searches that I am attempting should not require any scopes as they require no user data.
Any help appreciated 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:12
Top Results From Across the Web
Personal Access Token in Github not working - Stack Overflow
I have a private repository that I have a dependency on, using https://github.com... in my package.json. I have ssh set up on my...
Read more >Help! Personal Access Tokens not working : r/github - Reddit
Hello! I'm attempting to push something to github but I get failed authentications, either cannot find username and password, ...
Read more >Troubleshooting Invalid Access Tokens - Twilio Support
Verify the Access Token Structure · Uses Unix epoch timestamp · Ensure server system clock not skewed · TTL cannot be greater than...
Read more >Oauth/token not working - Auth0 Community
My oauth/token flow does not work. When I try to authenticate with valid user and password, I get a strange response from the...
Read more >Troubleshooting OAuth App access token request errors
To solve this error, make sure you have the correct credentials for your OAuth App. Double check the client_id and client_secret to make...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes. I’ve had success with this. I use a helper in my app to handle the credential flow.
@SnowPrimate You’re welcome! Yes that is the right idea. To build a completely stateless application that does what you want when you run it or on schedule, you’ll need to save your refresh token once and inject it into your app or program on start/whenever it runs. Possible options to store this are:
Here’s the general idea
let instance = new SpotifyWebApi({...})
instance.refreshAccessToken()
and set the access token on the SpotifyWebApi instanceinstance.setAccessToken(access_token)
. Else proceed to next step on a 2xx response.Refs: