こんにちは,しまさん(@shimasan0x00)です.
最近ApexLegendsというバトルロイヤルのゲームにハマっており,日々闘争に明け暮れています.
PC版でフィールドに飛び降りてはやられ,フィールドに降りてはやられを繰り返しているのですが,ふとApexにAPIあれば色々統計とか見れて面白いだろうなぁと思ったらありました.
LoLとかもあるのでもしかしたら…と思って調べてみて正解でしたね.
ただ,Documentに関しては「Hit those endpoints, it’s self documenting. :)」とのことでしたのでとりあえずAPIを叩いてみて確かめていきたいと思います.
環境
- macOS 10.15 Catalina
- Python3.6.8
スポンサーリンク
APIキーの生成
まずはAPIキーを作成するためにアカウントを作成していきます.
なお,1minで30requestまでなのは注意してください.

まずはサイトに飛んだら「REGISTER」からアカウントを登録をしてください.

そしたらアプリケーションを作成します.

必要事項を記入し,「CreateApp」すると下の方にAPIキーが出てくるのでしっかり保存しておきましょう!
スポンサーリンク
ライブラリのインポート
from pprint import pprint
import os
import sys
import json
import requests
APIを叩く
まずはベースURLを用意しておきます.
base_url = "https://public-api.tracker.gg/v2/apex/standard/"
Get an Apex Legends player’s profile stats (v2)
GET https://public-api.tracker.gg/v2/apex/standard/profile/{platform}/{platformUserIdentifier}
platform : The platform slug, one of: ‘origin’, ‘xbl’, ‘psn’.
platformUserIdentifier : The user’s handle on the platform, ie. an Origin ID, Xbox Live gamertag, PSN ID, etc.
では叩くプログラムと私のアカウントで実行した結果を示します.
params = {"TRN-Api-Key":"API-KEY"}
endpoint = "profile/origin/villager_0x00"
session = requests.Session()
req = session.get(base_url+endpoint,params=params)
print(req.status_code)
req.close()
res = json.loads(req.text)
pprint(res)
{'data': {'availableSegments': [{'attributes': {}, 'type': 'legend'}],
'expiryDate': '2020-02-27T07:09:02.4492362+00:00',
'metadata': {'activeLegend': 'legend_9',
'activeLegendName': 'Octane',
'currentSeason': 2},
'platformInfo': {'additionalParameters': None,
'avatarUrl': 'https://secure.download.dm.origin.com/production/avatar/prod/1/599/208x208.JPEG',
'platformSlug': 'origin',
'platformUserHandle': 'villager_0x00',
'platformUserId': 'villager_0x00',
'platformUserIdentifier': 'villager_0x00'},
'segments': [{'attributes': {},
'expiryDate': '2020-02-27T07:09:02.4492362+00:00',
'metadata': {'name': 'Lifetime'},
'stats': {'kills': {'category': None,
'displayCategory': 'Combat',
'displayName': 'Kills',
'displayType': 'Unspecified',
'displayValue': '34',
'metadata': {},
'percentile': 38.0,
'rank': None,
'value': 34.0},
'level': {'category': None,
'displayCategory': 'Combat',
'displayName': 'Level',
'displayType': 'Unspecified',
'displayValue': '50',
'metadata': {},
'percentile': 49.0,
'rank': None,
'value': 50.0},
'rankScore': {'category': None,
'displayCategory': 'Game',
'displayName': 'Rank Score',
'displayType': 'Unspecified',
'displayValue': '0',
'metadata': {'iconUrl': 'https://trackercdn.com/cdn/apex.tracker.gg/ranks/bronze4.png'},
'percentile': None,
'rank': None,
'value': 0.0}},
'type': 'overview'},
{'attributes': {'id': 'legend_9'},
'expiryDate': '2020-02-27T07:09:02.4492362+00:00',
'metadata': {'bgImageUrl': 'https://trackercdn.com/cdn/apex.tracker.gg/legends/octane-concept-bg-small.jpg',
'imageUrl': 'https://trackercdn.com/cdn/apex.tracker.gg/legends/octane-tile.png',
'isActive': True,
'name': 'Octane',
'tallImageUrl': 'https://trackercdn.com/cdn/apex.tracker.gg/legends/octane-tall.png'},
'stats': {'kills': {'category': None,
'displayCategory': 'Combat',
'displayName': 'Kills',
'displayType': 'Unspecified',
'displayValue': '34',
'metadata': {},
'percentile': 36.0,
'rank': None,
'value': 34.0},
'passiveHealthRegenerated': {'category': None,
'displayCategory': 'Game',
'displayName': 'Passive '
'Health '
'Regenerated',
'displayType': 'Unspecified',
'displayValue': '4,005',
'metadata': {},
'percentile': 96.0,
'rank': None,
'value': 4005.0}},
'type': 'legend'}],
'userInfo': {'countryCode': None,
'customAvatarUrl': None,
'isInfluencer': False,
'isPremium': False,
'isVerified': False,
'socialAccounts': []}}}
Search for an Apex Legends player
GET https://public-api.tracker.gg/v2/apex/standard/search
platform : The platform slug, one of: ‘origin’, ‘xbl’, ‘psn’.
query : The user’s handle on the platform, ie. an Origin ID, Xbox Live gamertag, PSN ID, etc.
では叩くプログラムと私のアカウントで実行した結果を示します.
endpoint = "search"
params = {"TRN-Api-Key":"API-KEY",
"platform":"origin",
"query":"villager_0x00"}
session = requests.Session()
req = session.get(base_url+endpoint,params=params)
print(req.status_code)
req.close()
res = json.loads(req.text)
pprint(res)
{'data': [{'additionalParameters': None,
'avatarUrl': '',
'platformId': 5,
'platformSlug': 'origin',
'platformUserHandle': 'villager_0x00',
'platformUserId': 'villager_0x00',
'platformUserIdentifier': 'villager_0x00'}]}
Get an Apex Legends player’s match history broken up by session
GET https://public-api.tracker.gg/v2/apex/standard/profile/{platform}/{platformUserIdentifier}/sessions
platform : The platform slug, one of: ‘origin’, ‘xbl’, ‘psn’.
platformUserIdentifier : The user’s handle on the platform, ie. an Origin ID, Xbox Live gamertag, PSN ID, etc.
では叩くプログラムと私のアカウントで実行した結果を示します.
endpoint = "profile/origin/villager_0x00/sessions"
params = {"TRN-Api-Key":"API-KEY"}
session = requests.Session()
req = session.get(base_url+endpoint,params=params)
print(req.status_code)
req.close()
res = json.loads(req.text)
pprint(res)
{'data': {'expiryDate': '2020-02-27T07:43:32.347284+00:00',
'items': [{'matches': [{'id': '1cf03c76-6cfe-4fdf-8ff2-f3ace2c39078',
'metadata': {'character': {'displayValue': 'Octane',
'value': 9},
'characterIconUrl': {'displayValue': 'Octane',
'value': 'https://trackercdn.com/cdn/apex.tracker.gg/legends/octane-tile.png'},
'characterStats': {'displayValue': '',
'value': ['passiveHealthRegenerated']},
'endDate': {'displayValue': '2020-02-27T06:26:38.4498300Z',
'value': '2020-02-27T06:26:38.44983Z'},
'legend': {'displayValue': 'Octane',
'value': 9},
'legendBigImageUrl': {'displayValue': 'Octane',
'value': 'https://trackercdn.com/cdn/apex.tracker.gg/legends/octane-tile.png'},
'legendStats': {'displayValue': '',
'value': ['passiveHealthRegenerated']},
'result': {'displayValue': 'Unknown',
'value': 'unknown'}},
'stats': {'kills': {'category': 'combat',
'displayCategory': 'Combat',
'displayName': 'Kills',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'level': {'category': 'combat',
'displayCategory': 'Combat',
'displayName': 'Level',
'displayType': 'Number',
'displayValue': '50',
'metadata': {},
'percentile': None,
'rank': None,
'value': 50},
'passiveHealthRegenerated': {'category': None,
'displayCategory': None,
'displayName': 'Passive '
'Health '
'Regenerated',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'rankScore': {'category': 'game',
'displayCategory': 'Game',
'displayName': 'Rank '
'Score',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'rankScoreChange': {'category': 'game',
'displayCategory': 'Game',
'displayName': 'Rank '
'Score '
'Change',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'specific3': {'category': 'game',
'displayCategory': 'Game',
'displayName': 'Legend '
'Specific '
'3',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0}}}],
'metadata': {'duration': {'displayValue': '00:10:00',
'value': '00:10:00'},
'endDate': {'displayValue': '2020-02-27T06:26:38.4498300Z',
'value': '2020-02-27T06:26:38.44983Z'},
'isActive': {'displayValue': 'False',
'value': False},
'startDate': {'displayValue': '2020-02-27T06:16:38.4498300Z',
'value': '2020-02-27T06:16:38.44983Z'}},
'playlists': [],
'stats': {'kills': {'category': 'combat',
'displayCategory': 'Combat',
'displayName': 'Kills',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'rankScore': {'category': 'game',
'displayCategory': 'Game',
'displayName': 'Rank Score',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0},
'rankScoreChange': {'category': 'game',
'displayCategory': 'Game',
'displayName': 'Rank Score '
'Change',
'displayType': 'Number',
'displayValue': '0',
'metadata': {},
'percentile': None,
'rank': None,
'value': 0}}}]}}
スポンサーリンク
さいごに
今回はとりあえずApex APIを叩いてみて返ってくる値を確認してみました.
上手いプレイヤーのstatsを確認してみて使用率の高いレジェンドを見つけたり,自分の成長をデータから確認したりできそうで,この先が楽しみです.