You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this point, I'm simply trying to get a token using the Client Credentials flow. The code is running in a page locally on my computer (so that my client keys aren't exposed to the world). I have included below the content of the linked gist for convenience. Although I can use the curl method successfully, this method fails. One person attempted to help me troubleshoot in issue #321, but without success, so I'm hoping for a repo member to offer a suggestion.
Please advise. Thanks.
Included in an html file using <script src="js/spotify-test.js"></script>:
(()=>{constmyClientInfo={// but using actual client ID and secret valuesclientID: '<client_id>',clientSecret: '<client_secret>'};constmyAuthUrl=newURL('https://accounts.spotify.com/api/token');constmyAuthHeaders={'Content-Type': 'application/x-www-form-urlencoded',Authorization: `Basic ${btoa(`${myClientInfo.clientID}:${myClientInfo.clientSecret}`)}`// Won't work for unicode characters, but I think the Client ID is always ASCII};constmyAuthQueryParams={grant_type: 'client_credentials'};letmyAuthFormBody=newFormData();appendObjToFormBody(myAuthQueryParams,myAuthFormBody);constmyAuthInit={method: 'POST',headers: myAuthHeaders,body: myAuthFormBody,mode: 'no-cors'};constmyAuthRequest=newRequest(myAuthUrl,myAuthInit);fetch(myAuthRequest).then(res=>{if(res.ok){returnres.json();}thrownewError('Network response was not ok.');}).then(data=>console.log(data)).catch(err=>console.log(`Fetch problem: ${err}`));functionappendObjToFormBody(obj,form){for(letpropinobj){if(obj.hasOwnProperty(prop)){form.append(prop,obj[prop]);}}}})();
Issue found on 8 August 2017.
Endpoint(s):
POST https://accounts.spotify.com/api/token/Scope(s):
Steps to reproduce:
See code at this gist
Expected behaviour:
A token is returned.
Actual behaviour:
400 Server Error (consistently)
At this point, I'm simply trying to get a token using the Client Credentials flow. The code is running in a page locally on my computer (so that my client keys aren't exposed to the world). I have included below the content of the linked gist for convenience. Although I can use the
curlmethod successfully, this method fails. One person attempted to help me troubleshoot in issue #321, but without success, so I'm hoping for a repo member to offer a suggestion.Please advise. Thanks.
Included in an html file using
<script src="js/spotify-test.js"></script>: