我无论如何都不是程序员或程序员。我只是想使用Riot api将我的一些传奇联盟数据输入到zapier中,以便在其他地方使用。我可以很好地获得json数据,只是它为每个stat返回10个数据点。这是我用来获取数据的代码。
fetch('https://na.api.pvp.net/api/lol/na/v1.3/game/by-summoner/61645956/recent?api_key=<myapikey>')
.then(function(res) {
return res.json();
})
.then(function(json) {
callback(null, json);
})
.catch(callback);
它返回这个数组:(我不得不剪掉它的一部分来发布这个,它太长了。(
{
"summonerId":61645956,
"games":[
{
"gameId":2305710206,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":200,
"championId":89,
"spell1":14,
"spell2":4,
"level":30,
"ipEarned":62,
"createDate":1475123835392,
"fellowPlayers":[
{
"summonerId":26402335,
"teamId":100,
"championId":122
},
{
"summonerId":51664526,
"teamId":100,
"championId":81
},
{
"summonerId":38071418,
"teamId":200,
"championId":103
},
{
"summonerId":36515003,
"teamId":200,
"championId":18
},
{
"summonerId":48012068,
"teamId":200,
"championId":48
},
{
"summonerId":48064897,
"teamId":100,
"championId":143
},
{
"summonerId":45687834,
"teamId":200,
"championId":36
},
{
"summonerId":50239478,
"teamId":100,
"championId":120
},
{
"summonerId":30496298,
"teamId":100,
"championId":1
}
],
"stats":{
"level":13,
"goldEarned":9165,
"numDeaths":5,
"minionsKilled":47,
"championsKilled":3,
"goldSpent":8725,
"totalDamageDealt":26070,
"totalDamageTaken":25068,
"team":200,
"win":false,
"largestMultiKill":1,
"physicalDamageDealtPlayer":8335,
"magicDamageDealtPlayer":10398,
"physicalDamageTaken":15010,
"magicDamageTaken":6577,
"timePlayed":2033,
"totalHeal":2665,
"totalUnitsHealed":5,
"assists":10,
"item0":3401,
"item1":3190,
"item2":2049,
"item3":1031,
"item4":3111,
"item5":3751,
"item6":3364,
"magicDamageDealtToChampions":3997,
"physicalDamageDealtToChampions":2654,
"totalDamageDealtToChampions":7461,
"trueDamageDealtPlayer":7336,
"trueDamageDealtToChampions":810,
"trueDamageTaken":3480,
"wardKilled":2,
"wardPlaced":22,
"totalTimeCrowdControlDealt":125,
"playerRole":2,
"playerPosition":4,
"visionWardsBought":1
}
},
{
"gameId":2305656152,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":100,
"championId":98,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":51,
"createDate":1475121422227,
"fellowPlayers":[
{
"summonerId":44847062,
"teamId":200,
"championId":222
},
{
"summonerId":35024451,
"teamId":200,
"championId":75
},
{
"summonerId":36515003,
"teamId":100,
"championId":81
},
{
"summonerId":26655780,
"teamId":100,
"championId":77
},
{
"summonerId":22046951,
"teamId":200,
"championId":161
},
{
"summonerId":37418996,
"teamId":100,
"championId":112
},
{
"summonerId":37164256,
"teamId":200,
"championId":121
},
{
"summonerId":36386214,
"teamId":200,
"championId":412
},
{
"summonerId":70059201,
"teamId":100,
"championId":122
}
],
"stats":{
"level":11,
"goldEarned":6345,
"numDeaths":4,
"minionsKilled":33,
"championsKilled":1,
"goldSpent":5750,
"totalDamageDealt":17563,
"totalDamageTaken":15701,
"team":100,
"win":false,
"largestMultiKill":1,
"physicalDamageDealtPlayer":9109,
"magicDamageDealtPlayer":1575,
"physicalDamageTaken":6874,
"magicDamageTaken":6798,
"timePlayed":1519,
"totalHeal":2132,
"totalUnitsHealed":3,
"assists":8,
"item0":3401,
"item1":3047,
"item2":2049,
"item3":3105,
"item6":3341,
"magicDamageDealtToChampions":1081,
"physicalDamageDealtToChampions":3906,
"totalDamageDealtToChampions":4988,
"trueDamageDealtPlayer":6878,
"trueDamageTaken":2029,
"wardKilled":2,
"wardPlaced":11,
"totalTimeCrowdControlDealt":112,
"playerRole":2,
"playerPosition":4
}
},
{
"gameId":2305599567,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":100,
"championId":267,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":117,
"createDate":1475119366312,
"fellowPlayers":[
{
"summonerId":36515003,
"teamId":100,
"championId":236
},
{
"summonerId":24318381,
"teamId":200,
"championId":121
},
{
"summonerId":58801818,
"teamId":100,
"championId":48
},
{
"summonerId":71530149,
"teamId":100,
"championId":85
},
{
"summonerId":429991,
"teamId":200,
"championId":26
},
{
"summonerId":36467378,
"teamId":200,
"championId":110
},
{
"summonerId":80651936,
"teamId":100,
"championId":64
},
{
"summonerId":21785827,
"teamId":200,
"championId":115
},
{
"summonerId":54995317,
"teamId":200,
"championId":114
}
],
"stats":{
"level":18,
"goldEarned":14932,
"numDeaths":6,
"minionsKilled":32,
"goldSpent":13325,
"totalDamageDealt":42834,
"totalDamageTaken":28128,
"team":100,
"win":true,
"physicalDamageDealtPlayer":17326,
"magicDamageDealtPlayer":24972,
"physicalDamageTaken":18318,
"magicDamageTaken":9570,
"timePlayed":2621,
"totalHeal":25516,
"totalUnitsHealed":5,
"assists":25,
"item0":3092,
"item1":3190,
"item2":2045,
"item3":3117,
"item4":3504,
"item5":3050,
"item6":3364,
"magicDamageDealtToChampions":10608,
"physicalDamageDealtToChampions":1632,
"totalDamageDealtToChampions":12241,
"trueDamageDealtPlayer":535,
"trueDamageTaken":240,
"wardKilled":3,
"wardPlaced":26,
"totalTimeCrowdControlDealt":269,
"playerRole":2,
"playerPosition":4,
"totalDamageDealtToBuildings":5540,
"visionWardsBought":3
}
},
{
"gameId":2305593891,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":200,
"championId":26,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":96,
"createDate":1475116337677,
"fellowPlayers":[
{
"summonerId":59240130,
"teamId":200,
"championId":90
},
{
"summonerId":37737286,
"teamId":200,
"championId":5
},
{
"summonerId":48134049,
"teamId":100,
"championId":25
},
{
"summonerId":52001343,
"teamId":200,
"championId":104
},
{
"summonerId":23929258,
"teamId":100,
"championId":67
},
{
"summonerId":36515003,
"teamId":200,
"championId":236
},
{
"summonerId":71539264,
"teamId":100,
"championId":133
},
{
"summonerId":73074002,
"teamId":100,
"championId":103
},
{
"summonerId":57259369,
"teamId":100,
"championId":23
}
],
"stats":{
"level":15,
"goldEarned":10822,
"numDeaths":5,
"turretsKilled":2,
"minionsKilled":46,
"championsKilled":1,
"goldSpent":9800,
"totalDamageDealt":60871,
"totalDamageTaken":14379,
"team":200,
"win":true,
"largestMultiKill":1,
"physicalDamageDealtPlayer":7532,
"magicDamageDealtPlayer":53339,
"physicalDamageTaken":7061,
"magicDamageTaken":6431,
"timePlayed":2090,
"totalHeal":8278,
"totalUnitsHealed":5,
"assists":14,
"item0":3092,
"item1":3158,
"item2":2049,
"item3":3512,
"item4":3165,
"item6":3364,
"magicDamageDealtToChampions":8992,
"physicalDamageDealtToChampions":1933,
"totalDamageDealtToChampions":10925,
"trueDamageTaken":886,
"wardKilled":1,
"wardPlaced":11,
"totalTimeCrowdControlDealt":201,
"playerRole":2,
"playerPosition":4,
"totalDamageDealtToBuildings":1733,
"visionWardsBought":2
}
},
{
"gameId":2305548000,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":100,
"championId":26,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":76,
"createDate":1475113731759,
"fellowPlayers":[
{
"summonerId":50558512,
"teamId":100,
"championId":81
},
{
"summonerId":29276199,
"teamId":100,
"championId":51
},
{
"summonerId":36654393,
"teamId":200,
"championId":240
},
{
"summonerId":36515003,
"teamId":100,
"championId":223
},
{
"summonerId":76800634,
"teamId":200,
"championId":11
},
{
"summonerId":50445070,
"teamId":200,
"championId":222
},
{
"summonerId":52201449,
"teamId":200,
"championId":4
},
{
"summonerId":11625,
"teamId":100,
"championId":106
},
{
"summonerId":30564904,
"teamId":200,
"championId":89
}
],
"stats":{
"level":13,
"goldEarned":8724,
"numDeaths":2,
"turretsKilled":1,
"minionsKilled":38,
"championsKilled":1,
"goldSpent":6360,
"totalDamageDealt":52177,
"totalDamageTaken":7009,
"team":100,
"win":true,
"neutralMinionsKilled":6,
"largestMultiKill":1,
"physicalDamageDealtPlayer":8451,
"magicDamageDealtPlayer":43726,
"physicalDamageTaken":5381,
"magicDamageTaken":1470,
"timePlayed":1519,
"totalHeal":1931,
"totalUnitsHealed":1,
"assists":7,
"item0":3092,
"item1":3158,
"item2":2049,
"item3":3108,
"item4":3802,
"item5":1052,
"item6":3364,
"magicDamageDealtToChampions":5029,
"physicalDamageDealtToChampions":974,
"totalDamageDealtToChampions":6004,
"trueDamageTaken":157,
"wardPlaced":14,
"neutralMinionsKilledEnemyJungle":3,
"neutralMinionsKilledYourJungle":3,
"totalTimeCrowdControlDealt":214,
"playerRole":2,
"playerPosition":4,
"totalDamageDealtToBuildings":5840,
"visionWardsBought":1
}
},
{
"gameId":2305542650,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":200,
"championId":25,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":82,
"createDate":1475111487614,
"fellowPlayers":[
{
"summonerId":49111930,
"teamId":100,
"championId":17
},
{
"summonerId":29149315,
"teamId":200,
"championId":107
},
{
"summonerId":36515003,
"teamId":200,
"championId":104
},
{
"summonerId":69370945,
"teamId":100,
"championId":115
},
{
"summonerId":25972662,
"teamId":100,
"championId":53
},
{
"summonerId":73929624,
"teamId":200,
"championId":2
},
{
"summonerId":36783010,
"teamId":100,
"championId":236
},
{
"summonerId":35386736,
"teamId":200,
"championId":61
},
{
"summonerId":29070094,
"teamId":100,
"championId":5
}
],
"stats":{
"level":14,
"goldEarned":10650,
"numDeaths":1,
"barracksKilled":1,
"turretsKilled":2,
"minionsKilled":34,
"championsKilled":2,
"goldSpent":8650,
"totalDamageDealt":51368,
"totalDamageTaken":10392,
"killingSprees":1,
"largestKillingSpree":2,
"team":200,
"win":true,
"neutralMinionsKilled":1,
"largestMultiKill":1,
"physicalDamageDealtPlayer":10713,
"magicDamageDealtPlayer":40654,
"physicalDamageTaken":3723,
"magicDamageTaken":6620,
"timePlayed":1698,
"totalHeal":1437,
"totalUnitsHealed":1,
"assists":16,
"item0":3092,
"item1":2031,
"item2":2049,
"item3":3157,
"item4":3020,
"item5":3105,
"item6":3364,
"magicDamageDealtToChampions":10747,
"physicalDamageDealtToChampions":1355,
"totalDamageDealtToChampions":12103,
"trueDamageTaken":48,
"wardKilled":3,
"wardPlaced":18,
"neutralMinionsKilledYourJungle":1,
"totalTimeCrowdControlDealt":151,
"playerRole":2,
"playerPosition":4,
"bountyLevel":2,
"totalDamageDealtToBuildings":5974
}
},
{
"gameId":2305309550,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":200,
"championId":26,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":230,
"createDate":1475109305903,
"fellowPlayers":[
{
"summonerId":58049719,
"teamId":100,
"championId":412
},
{
"summonerId":57761286,
"teamId":100,
"championId":18
},
{
"summonerId":60661724,
"teamId":200,
"championId":51
},
{
"summonerId":69852470,
"teamId":200,
"championId":245
},
{
"summonerId":35240348,
"teamId":200,
"championId":41
},
{
"summonerId":64891806,
"teamId":100,
"championId":99
},
{
"summonerId":19810065,
"teamId":200,
"championId":154
},
{
"summonerId":72219120,
"teamId":100,
"championId":64
},
{
"summonerId":29290889,
"teamId":100,
"championId":19
}
],
"stats":{
"level":13,
"goldEarned":9891,
"numDeaths":2,
"minionsKilled":46,
"championsKilled":2,
"goldSpent":8925,
"totalDamageDealt":54060,
"totalDamageTaken":8547,
"team":200,
"win":true,
"neutralMinionsKilled":7,
"largestMultiKill":1,
"physicalDamageDealtPlayer":5671,
"magicDamageDealtPlayer":48342,
"physicalDamageTaken":3440,
"magicDamageTaken":5107,
"timePlayed":1676,
"totalHeal":4528,
"totalUnitsHealed":2,
"assists":17,
"item0":3092,
"item1":3158,
"item2":2049,
"item3":3165,
"item4":3105,
"item5":1028,
"item6":3364,
"magicDamageDealtToChampions":8314,
"physicalDamageDealtToChampions":1984,
"totalDamageDealtToChampions":10299,
"trueDamageDealtPlayer":45,
"wardKilled":1,
"wardPlaced":15,
"neutralMinionsKilledEnemyJungle":7,
"totalTimeCrowdControlDealt":256,
"playerRole":2,
"playerPosition":4,
"totalDamageDealtToBuildings":2077,
"visionWardsBought":1
}
},
{
"gameId":2305304640,
"invalid":false,
"gameMode":"CLASSIC",
"gameType":"MATCHED_GAME",
"subType":"RANKED_SOLO_5x5",
"mapId":11,
"teamId":100,
"championId":89,
"spell1":3,
"spell2":4,
"level":30,
"ipEarned":64,
"createDate":1475107215636,
"fellowPlayers":[
{
"summonerId":34093650,
"teamId":100,
"championId":75
},
但在zapier中,它的格式为:https://i.stack.imgur.com/QA876.jpg
我可以向该代码添加什么,或者运行不同的操作代码来获得每个字段的第一个值?如果这有道理的话。谢谢
不要像callback(null, json)
那样返回完整的json值,而是尝试使用属性games
和数组索引[0]
来获得像callback(null, json.games[0])
那样的数据子集。
注意,如果你想在新游戏上触发(IE:在玩完每个游戏后,启动一个工作流(,返回数组,Zapier将监视新游戏(尽管你可能需要指定一个特定的属性作为id
,因为它不太可能理解gameId
是标识符(。IE:就像这个callback(null, json.games)
。