【问题标题】:Why is this nested request not running in Node.js with Spotify API?为什么这个嵌套请求没有在带有 Spotify API 的 Node.js 中运行?
【发布时间】:2020-04-17 16:54:11
【问题描述】:

我正在使用授权代码流程让用户登录并允许我访问并在他们的帐户上创建播放列表。我已经按照文档进行操作,现在我正在尝试阅读用户播放列表,但我的嵌套请求没有运行。这是我的代码:

request.get(options, function(error, response, body) {
            console.log(body);
            if(response){
              request.get({url: 'https://api.spotify.com/v1/users/'+body.id+'/playlists',
                          headers:{ 'Authorization': 'Bearer ' + access_token },
                          function(error, res){
                            //var playlists = JSON.parse(response.body);
                            console.log("this code runs");
                          }
            })
            }
            
          });
  

到目前为止,我检索了用户 ID,它确实登录到控制台,然后将用户 ID 传递给下一个端点,但第二个请求没有运行。 I am using this endpoint.

【问题讨论】:

    标签: javascript node.js express spotify


    【解决方案1】:

    这不起作用的原因是因为我将函数作为选项对象中的属性而不是第二个参数传递。这是固定代码:

    request.get({
      url: 'https://api.spotify.com/v1/users/' + body.id + '/playlists',
      headers: { 'Authorization': 'Bearer ' + access_token }
    },
      function (error, response, body) {
        //var playlists = JSON.parse(response.body);
        console.log("this code runs");
      }
    )

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      相关资源
      最近更新 更多