Spotify API Illegal redirect_uri
Asked Answered
D

2

8

I'm trying to progress through the Spotify developer API tutorial but when I try to access the user login page I get this error. I've triple checked that the URI in the code matches the one on MyApplications page but it still won't work. Here's the script,

var express = require('express'); // Express web server framework
var request = require('request'); // "Request" library
var querystring = require('querystring');
var cookieParser = require('cookie-parser');

var client_id = id;
var client_secret = secret;
var redirect_uri = "http://localhost:8888/callback";

Image of error code and MyApplications page

I'm not sure what I'm doing wrong but I've been going over it for hours now, can someone help?

Delaine answered 22/3, 2018 at 0:36 Comment(0)
M
12

You need your redirect URIs to be exactly the same. The URI you have registered in the Dashboard is http://localhost:8888/callback/ with a trailing slash. The version you use in your code does not have the trailing slash. Just change your redirect_uri to be:

var redirect_uri = "http://localhost:8888/callback/";

You can verify that this works with this example authorize URL I made: https://accounts.spotify.com/en/authorize?client_id=df5c5a57b94a4817ae3ac4760c701983&redirect_uri=http:%2F%2Flocalhost:8888%2Fcallback%2F&scope=streaming%20user-read-birthdate%20user-read-private%20user-modify-playback-state&response_type=token&show_dialog=true

Melisma answered 23/3, 2018 at 11:53 Comment(2)
INVALID_CLIENT: Invalid redirect URIPennywise
You can check it like that: accounts.spotify.com/en/… Just replace [YOUR_CLIENT_ID] and [YOUR_REDIRECT_URI], then it should work.Scoggins
B
6

I just needed to restart my Node server!

Steps to fix:

  1. Ensure your redirect_uri has a trailing slash after callback.
    Mine is: http://localhost:8888/callback/
  2. Ensure your project in your dashboard has the EXACT same URL as the one in step 1 under the 'redirect URI' section. Make sure to press the green 'ADD' button to the right and the 'SAVE' button at the bottom.
  3. Save your file and RESTART YOUR NODE SERVER. this may seem trivial. But took me 30 minutes until I finally tried restarting it.
Bashuk answered 14/8, 2020 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.