【发布时间】:2019-11-25 05:05:19
【问题描述】:
我正在尝试使用以下代码将用户重定向到 Spotify 帐户服务的 /authorize 端点:
var state = generateRandomString(16);
function login() {
var client_id = '02a53684fa064d66a9dff00afeb42fd7';
var redirect_uri = 'https://localhost:3000';
var url = new URL('https://accounts.spotify.com/authorize');
var scope = 'user-read-private user-read-email';
var params = {
client_id: client_id,
response_type: 'token',
redirect_uri: redirect_uri,
scope: scope,
state: state
};
url.search = new URLSearchParams(params).toString();
fetch(url, {
mode: 'no-cors'
}).then(response => response.json())
.catch(error => alert(error));
}
这样成功创建了请求url:
尽管已成功请求授权访问,但为什么我无法在浏览器上看到 Spotify 登录屏幕?
【问题讨论】:
-
这是在浏览器上还是在服务器上(就像节点一样)?在服务器上,here is an example 他们调用重定向以打开 Spotify 登录屏幕。
-
@KevinGuebert 他们在示例中使用了 ExpressJS。我没有使用它。我没有进行 fetch 调用,而是使用了
window.location = url;,这似乎有效。 -
不错!很高兴你得到它!
标签: javascript oauth spotify