简体   繁体   English

对 Spotify Web API 的身份验证请求被拒绝

[英]Authentication Request to Spotify Web API Rejected

I am trying to send an authentication request to Login to Spotify.我正在尝试向登录 Spotify 发送身份验证请求。

This is run through local host by a javascript XMLHttpRequest.这是由 javascript XMLHttpRequest 通过本地主机运行的。 However all I ever receive is an error message stating:但是,我收到的只是一条错误消息,说明:

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

No 'Access-Control-Allow-Origin' header is present on the requested resource.请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin "localhost" is therefore not allowed access."因此不允许访问源“localhost”。”

I tried setting the header doing xmlrequest.setRequestHeader("Access-Control-Allow-Origin", "*");我尝试设置标题做xmlrequest.setRequestHeader("Access-Control-Allow-Origin", "*"); however this did not work.然而这并没有奏效。

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.如果是这样,您需要做的是将用户重定向到您在上面给出的 URL。 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.流程完成后,用户将被重定向到您的重定向回调 URL。 If successful, the authorization code will be one of the query parameters when then the user is redirected back to your server.如果成功,当用户被重定向回您的服务器时,授权码将是查询参数之一。

Documentation: Authorization Code flow文档: 授权码流程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM