为什么api查询会返回一个空数组?

时间:2018-12-17 20:25:18

标签: javascript node.js npm

当我使用npm请求调用此api时,我返回一个空数组。我已经加载了请求,并在页面顶部定义了内容的值(此处未显示)。我也在这里更改了api密钥。这三件事都不是问题(请求,内容或api密钥)。

当我使用Chrome://inspect运行调试器时,它的错误/响应显示为失败,

  

err = null,响应= IncomingMessage {_visibleState:ReadableState,   可读:假,域:空,_events:{…},_eventsCount:4,…},正文   ='

代码如下:

function concertThis(){


  var queryUrl = "https://rest.bandsintown.com/artists/" + content + 
  "/events?app_id=api_key"

  console.log(queryUrl);

  request(queryUrl, function(err, response, body){
    if(!err && response.statusCode === 200){
        debugger;

       console.log("-------");
       console.log(JSON.parse(body));  

      }
    })

 }

这是我终端中的结果:

$ node liri.js concert-this mumford and sons
https://rest.bandsintown.com/artists/mumford+and+sons/events? 
app_id=api_key
-------
[]

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

我使用bandsintown api in-documentation execute进行了尝试,并返回了一个空数组。可能是Mumford and Sons没有任何即将发生的事件?您尝试过其他乐队吗?

Here is an example的肖恩·门德斯(Shawn Mendes)有事件,并且响应中有信息。

相关问题