对 Spotify Web API 的身份验证请求被拒绝 [英] Authentication Request to Spotify Web API Rejected

查看:46
本文介绍了对 Spotify Web API 的身份验证请求被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向登录 Spotify 发送身份验证请求.

I am trying to send an authentication request to Login to Spotify.

这是由 javascript XMLHttpRequest 通过本地主机运行的.但是,我收到的只是一条错误消息,说明:

This is run through local host by a javascript XMLHttpRequest. However all I ever receive is an error message stating:

XMLHttpRequest 无法加载 https://accounts.spotify.com/authorize/?q=undefined&type=code&client_id=9f5...ope=user-read-private%20user-read-email%20streaming&state=iKX8sdHHEML6BxRy.

XMLHttpRequest cannot load https://accounts.spotify.com/authorize/?q=undefined&type=code&client_id=9f5…ope=user-read-private%20user-read-email%20streaming&state=iKX8sdHHEML6BxRy.

请求的资源上不存在Access-Control-Allow-Origin"标头.因此,不允许访问源localhost"."

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "localhost" is therefore not allowed access."

我尝试通过 xmlrequest.setRequestHeader("Access-Control-Allow-Origin", "*"); 设置标头,但是这不起作用.

I tried setting the header doing xmlrequest.setRequestHeader("Access-Control-Allow-Origin", "*"); however this did not work.

推荐答案

如果我没理解错的话,您是在尝试从用户那里检索授权码.如果是这样,您需要做的是将用户重定向到您在上面给出的 URL.这将引导用户完成用户授予您的应用程序权限的流程.流程完成后,用户将被重定向到您的重定向回调 URL.如果成功,当用户被重定向回您的服务器时,授权码将是查询参数之一.

If I'm understanding you correctly, you're attempting to retrieve an authorization code from the user. If so, what you need to do is to redirect the user to the URL you've given above. This will take the user through a flow where the user grants your application permissions. When the flow is completed, the user is redirected to your redirect callback URL. If successful, the authorization code will be one of the query parameters when then the user is redirected back to your server.

文档:授权码流程

这篇关于对 Spotify Web API 的身份验证请求被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆