Reputation: 173
I've been trying to request an access code from spotify so that I can get an access token and refresh it but for some reason I'm getting an error saying "malformed or illegal request". I think it might have something to do with the redirect_uri. I'm not really sure at all how I'm supposed to format it and if it really matters. This is what I've been doing:
const authorize_url = "https://accounts.spotify.com/authorize";
request({url:authorize_url, form:{client_id: "6...a", response_type: "code", redirect_uri: "http://localhost:8888/callback", scope: "user-modify-playback-state"}}, function(code, error){
console.log(code);
console.log(error);
});
This is the example that they have on the api (the "state" variable is optional):
GET https://accounts.spotify.com/authorize?client_id=5fe01282e44241328a84e7c5cc169165&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user-read-private%20user-read-email&state=34fFs29kd09
And this is the end of the error message:
body: '<!DOCTYPE html>\n' +
'<html lang=en>\n' +
' <meta charset=utf-8>\n' +
' <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">\n' +
' <title>Error 400 (Bad Request)!!1</title>\n' +
' <style>\n' +
' *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n' +
' </style>\n' +
' <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n' +
' <p><b>400.</b> <ins>That’s an error.</ins>\n' +
' <p>Your client has issued a malformed or illegal request. <ins>That’s all we know.</ins>\n',
Upvotes: 0
Views: 3214
Reputation: 173
Problem fixed thanks to @portatlas Here's what I did:
const propertyObject = {client_id: "6...b", response_type: "code", redirect_uri: "http://localhost:8888", scope: "user-modify-playback-state"};
request.get({url:"https://accounts.spotify.com/authorize", qs:propertyObject}, function(code, error, state){
console.log(code);
console.log(state);
console.log(error);
});
Upvotes: 0
Reputation: 687
Per the documentation you should be making the request with query parameters instead of the form parameters. So make sure that your request is in the same format as the example you provided.
Upvotes: 3