【问题标题】:JSON syntax for Spotify Web APISpotify Web API 的 JSON 语法
【发布时间】:2018-11-23 22:02:22
【问题描述】:

我正在为一个项目使用 Spotify Web API,但我错过了一些东西,因为我得到了一个 400 错误,根据 Documentation 是一个语法问题。

代码是:

    function generatePlaylist(access_token) {

        $.ajax({
          url: 'https://api.spotify.com/v1/me/playlists',
          method: "POST",
          data: {"name": "New Playlist", "description": "New playlist description","public": false},

          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + access_token
          },

            success: function(response) {
                console.log("Success!");
            }
        });
    }

这是一个新手问题,但任何人都可以帮助我编写正确的 JSON 请求吗?你好!

【问题讨论】:

    标签: json spotify


    【解决方案1】:

    没关系,这是功能代码。只需要添加 JSON.stringify:

        function generatePlaylist(access_token) {
    
            $.ajax({
              url: 'https://api.spotify.com/v1/me/playlists',
              method: "POST",
              data: JSON.stringify({name: "test", public: false}),
    
              headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + access_token
              },
    
                success: function(response) {
                    console.log("Success!");
                }
            });
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 2015-07-11
      • 2015-05-18
      • 1970-01-01
      相关资源
      最近更新 更多