Getting authorized access error from Spotify with spotify

I'm trying to use the Spotify wrapper to use my app, I manage to hit Spotify's Account Service and the page to authorize the app to use a users spotify account information but I get an internal 500 server error:

index.js:6 POST https://accounts.spotify.com/en/authorize/accept 500 (Internal Server Error)

// Set up Spotify API wrapper
const scopes = ['user-read-private', 'user-read-email'];
const STATE_KEY = 'spotify_auth_state';

app.get('/login', (req, res) => {
  const state = generateRandomString(16);
  res.cookie(STATE_KEY, state);
  res.redirect(spotifyApi.createAuthorizeURL(scopes, state));
});

app.get('/callback', (req, res) => {
  const { code, state } = req.query;
  const storedState = req.cookies ? req.cookies[STATE_KEY] : null;

  if (state === null || state !== storedState) {
    res.redirect('/#/error/state mismatch');
  } else {
    res.clearCookie(STATE_KEY);

    spotifyApi
      .authorizationCodeGrant(code)
      .then(data => {
        const { expires_in, access_token, refresh_token } = data.body;

        // Set the access token on the API object to use it in later calls
        spotifyApi.setAccessToken(access_token);
        spotifyApi.setRefreshToken(refresh_token);

        spotifyApi.getMe().then(({ body }) => {
          console.log(body);
        });

        res.redirect('/search');
      })
      .catch(err => {
        res.redirect('/#/error/invalid token');
      });
  }
});

This is my endpoint on that page:

https://accounts.spotify.com/en/authorize?client_id=CLIENT_ID&response_type=code&redirect_uri=http:%2F%2Flocalhost:8888%2Fcallback%2F&scope=user-read-private%20user-read-email&state=k4ogwe4h53i00000

Not entirely sure what's happening. I thought it was initially a state mismatch but the state generated is fine. Having trouble pinpointing where the error is. Anyone have any suggestions?


You need to set your redirect URI in the developer dashboard, ensuring that it's exactly the same as the one you're using in your app.

We're aware of the poor error handling for the invalid redirect URI error and it's being fixed.

链接地址: http://www.djcxy.com/p/55682.html

上一篇: 如何使一个函数等待,直到使用node.js调用回调

下一篇: 使用Spotify获取来自Spotify的授权访问错误