Spotify API Illegal redirect_uri

10,337

Solution 1

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

Solution 2

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.
Share:
10,337
nmowery
Author by

nmowery

Updated on June 13, 2022

Comments

  • nmowery
    nmowery almost 2 years

    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?

  • activedecay
    activedecay over 5 years
    INVALID_CLIENT: Invalid redirect URI
  • novas1r1
    novas1r1 almost 2 years
    You can check it like that: accounts.spotify.com/en/… Just replace [YOUR_CLIENT_ID] and [YOUR_REDIRECT_URI], then it should work.