Riot API调用Node.js

时间:2017-03-01 16:45:13

标签: javascript node.js riot-games-api

js服务器从riot.developer运行一些基本的api调用。 我计划为每个召唤者/游戏提供比赛历史和统计数据。为此,我假设我需要匹配ID#s。

我有几个电话正在工作,但似乎已经遇到了这个问题。大概盯着我的屏幕太久了! 以下是我的具体请求代码,为清楚起见,此请求仅适用于匹配ID:

function(data, callback) {
    var URL = 'https://euw.api.pvp.net/api/lol/euw/v2.2/matchlist/by-summoner/' + data.id + 'seasons=SEASON2016&beginIndex=0&endIndex=40&api_key=' + api_key;
    request(URL, function (err, response, body) {
        if (response.statusCode == 200) {
            var json = json.parse(body);
            var matchId = 0;
            for (var c = 0; c < json['matches'].length; c++) {
                data.matches = json['matches'].matchId;
                data.matches = matchId;
                console.log(data.matches);
                callback(null, data);
            }
        } else {
            console.log('line 82');
        }

    });
},

我认为我遇到的问题与我表达data.matches的方式有关。或者说没有时间表?

data.idapi_key是在此功能之外定义的,并且正常运行。 无论如何,感谢你们能提供的任何帮助。

我应该提一下我安装了快速把手。

1 个答案:

答案 0 :(得分:0)

好的,我想我已经解决了这个问题。 (我花了太长时间!) 这是我编辑的功能:

    function(data, callback) {
    var URL = 'https://euw.api.pvp.net/api/lol/euw/v2.2/matchlist/by-summoner/' + data.id + '?seasons=SEASON2016&beginIndex=0&endIndex=40&api_key=' + api_key;
    request(URL, function(err, response, body) {
      if(response.statusCode == 200) {
        var json =JSON.parse(body);
        for(var c = 0; c < json ['matches'].length; c++) {
        data.matches = json['matches'][c].matchId;
        console.log(data.matches)
      };
        callback(null, data);
      } else {
        console.log('line 78');
    }
    })
    }

这在我的终端输出40匹配ID。只需要弄清楚如何立即添加索引; D