Spotify API Illegal redirect_uri

半世苍凉 提交于 2020-08-24 19:34:26

问题


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?


回答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




回答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.


来源:https://stackoverflow.com/questions/49418717/spotify-api-illegal-redirect-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!