Authentication Request to Spotify Web API Rejected

徘徊边缘 提交于 2019-12-25 03:26:20

问题


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

This is run through local host by a 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.

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

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


回答1:


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.

Documentation: Authorization Code flow



来源:https://stackoverflow.com/questions/24914853/authentication-request-to-spotify-web-api-rejected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!