Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

spotify-web-api-node authenticate user

spotify-web-api-node authenticate user

Hey guys, I'm trying to use the library "spotify-web-api-node" the function "getMe"  and when I use my token accountant (Spotify developer) it works but when the other accountant doesn't work and returns error 403.

Why happens this problem? 

 

I'm a novated in requests api

Thank you !!!

 

 

 

 

 

 

 

 

class User{
    login(req, res){
        res.redirect(spotifyApi.createAuthorizeURL(scopes));
    };
      
    callback(req, res){
        const error = req.query.error;
        const code = req.query.code;
        const state = req.query.state;
      
        if (error) {
          console.error('Callback Error:', error);
          res.send(`Callback Error: ${error}`);
          return;
        }
      
        spotifyApi
          .authorizationCodeGrant(code)
          .then(data => {
            const access_token = data.body['access_token'];
            const refresh_token = data.body['refresh_token'];
            const expires_in = data.body['expires_in'];
      
            spotifyApi.setAccessToken(access_token);
            spotifyApi.setRefreshToken(refresh_token);
      
            console.log('access_token:', access_token);
            console.log('refresh_token:', refresh_token);
      
            console.log(
              `Sucessfully retreived access token. Expires in ${expires_in} s.`
            );
            res.send('Success! You can now close the window.');
      
            setInterval(async () => {
              const data = await spotifyApi.refreshAccessToken();
              const access_token = data.body['access_token'];
      
              console.log('The access token has been refreshed!');
              console.log('access_token:', access_token);
              spotifyApi.setAccessToken(access_token);
            }, expires_in / 2 * 1000);
          })
          .catch(error => {
            console.error('Error getting Tokens:', error);
            res.send(`Error getting Tokens: ${error}`);
          });
      };

      
   async verifyUser(req, res){
    
    
    //const token = spotifyApi.getAccessToken();
    //res.json(spotifyApi.getAccessToken())
        
   await spotifyApi.getMe()
    .then(function(data) {
      res.json({"Some information about the authenticated user": data.body});
    }, function(err) {
        res.json({'Something went wrong!': err});
    });
     }
}

module.exports = new User();

 

 

 

 

 

 

 

Reply
0 Replies

Suggested posts