Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spotify API Illegal redirect_uri

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?

like image 605
nmowery Avatar asked Mar 22 '18 00:03

nmowery


2 Answers

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

like image 170
arirawr Avatar answered Sep 29 '22 18:09

arirawr


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.
like image 26
Ryan Russell Avatar answered Sep 29 '22 18:09

Ryan Russell