Announcements

Help Wizard

Step 1

NEXT STEP

INVALID_CLIENT: Invalid redirect URI

INVALID_CLIENT: Invalid redirect URI

 

 

 

 

 

const REDIRECT_URI = 'http://localhost:3000/callback';
const SCOPES = 'user-library-read user-read-playback-position';

// Redirect to Spotify authorization page
app.get('/login', (req, res) => {
const queryParams = querystring.stringify({
response_type: 'code',
client_id: CLIENT_ID,
redirect_uri: REDIRECT_URI,
scope: SCOPES,
});
res.redirect(`https://accounts.spotify.com/authorize?${queryParams}`);
});

// Callback route after user authorization
app.get('/callback', async (req, res) => {
const { code } = req.query;

try {
// Exchange authorization code for access token
const response = await axios.post('https://accounts.spotify.com/api/token', {
grant_type: 'authorization_code',
code,
redirect_uri: REDIRECT_URI,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
});

const accessToken = response.data.access_token;
// You can now use accessToken to make requests to the Spotify API on behalf of the user

res.send('Authorization successful! You can now make requests to the Spotify API.');
} catch (error) {
console.error('Error exchanging authorization code for access token:', error);
res.status(500).send('Error exchanging authorization code for access token');
}
});

 

 

 

 

 

Reply
1 Reply

At this page is working code and instructions.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random