Post 请求 Spotify API

Post request to Spotify API

我正在使用 Node.js 建立一个网站,我可以在 Spotify 中跳过曲目和排队歌曲(学习 nodeJS 和 Javascript 的项目)

这段代码在里面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);
        }
    });
});

但是,当我查看浏览器的控制台时,它显示:

Failed to load resource: the server responded with a status of 404 (Not Found) : 8888/[object%20Object]

这里的问题是:我应该向本地主机发送请求并将其路由到 spotify api 还是应该像我在这段代码中所做的那样直接向 spotify 发送请求?

如果是第二种,我实在想不通为什么不行。

我发现了!我仍然不确定为什么这不起作用,但是通过将代码更改为以下它起作用了。

document.getElementById('skip-song').addEventListener('click', function(){
  $.ajax({
    type: 'POST',
    url:'https://api.spotify.com/v1/me/player/next',
    headers: {'Authorization': "Bearer " + access_token}
  });
});