Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

javascript - Authentication Request to Spotify Web API Rejected

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...