Получение «неверного или недопустимого запроса» при запросе кода доступа у spotify - PullRequest
0 голосов
/ 07 апреля 2020

Я пытался запросить код доступа у spotify, чтобы я мог получить токен доступа и обновить его sh, но по какой-то причине я получаю сообщение об ошибке "неправильно сформированный или недопустимый запрос". Я думаю, что это может иметь какое-то отношение к redirect_uri. Я не совсем уверен, как я должен отформатировать это и если это действительно имеет значение. Это то, что я делал:

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);
});

Это пример, который они имеют на API (переменная "состояние" является необязательной):

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

И это конец сообщения об ошибке:

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',

Ответы [ 2 ]

2 голосов
/ 08 апреля 2020

Согласно документации вы должны делать запрос с параметрами запроса вместо параметров формы. Поэтому убедитесь, что ваш запрос имеет тот же формат, что и приведенный вами пример.

0 голосов
/ 09 апреля 2020

Проблема исправлена ​​благодаря @portatlas Вот что я сделал:

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);
});
...