Reputation: 535
I'm using Node.js to build an website where I can skip tracks and queue songs in Spotify (project for learning nodeJS and Javascript)
This code in inside index.html.
document.getElementById('skip-song').addEventListener('click', function(){
$.post({
url: 'https://api.spotify.com/v1/me/player/next',
headers: {
'Authorization': 'Bearer ' + access_token
},
success: function(response){
console.log(response.headers);
}
});
});
But, when I look on the console of the browser, it reads:
Failed to load resource: the server responded with a status of 404 (Not Found) : 8888/[object%20Object]
Question here is: should I be sending a request to the localhost and route it to spotify api or should I send a request directly to spotify like I'm doing in this code?
If it's the second, I can't really figure out why it doesn't work.
Upvotes: 0
Views: 1439
Reputation: 535
I've found out! I'm still not sure why that was not working, but by changing the code to the following it worked.
document.getElementById('skip-song').addEventListener('click', function(){
$.ajax({
type: 'POST',
url:'https://api.spotify.com/v1/me/player/next',
headers: {'Authorization': "Bearer " + access_token}
});
});
Upvotes: 2