The Fortnite tracker api is an excellent way to get your Fortnite battle royal stats, whilst there is no official api yet here is how to use the Fortnite tracker api in php.
Go to Fortnite tracker and get your api key here
Create a php file called fortnite.php
Add and edit the following making sure you add the console/platform (pc, xbl or psn) and players username on line 2. Then add your api key on line 7 where it says *API*KEY*HERE*.
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/CONSOLE/PLAYERUSERNAME"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'TRN-Api-Key: *API*KEY*HERE*' )); $response = curl_exec($ch); curl_close($ch); $fp = fopen("stats.json", "w"); fwrite($fp, $response); fclose($fp);
This will fetch the data using curl and save it into stats.json to prevent excess api calling. Learn what a json file is here.
To read the saved data (stats.json) use the following php code:
$data = json_decode(file_get_contents("stats.json")); $solo = $data->stats->p2;//solos data $duos = $data->stats->p10;//duos data $squads = $data->stats->p9;//squads data $solo_wins = $solo->top1->valueInt; $duos_wins = $duos->top1->valueInt; $squads_wins = $squads->top1->valueInt; $solo_matches = $solo->matches->valueInt; $duos_matches = $duos->matches->valueInt; $squads_matches = $squads->matches->valueInt; $solo_kd = $solo->kd->valueDec; $duos_kd = $duos->kd->valueDec; $squads_kd = $squads->kd->valueDec; $solo_games = $solo->matches->valueInt; $duos_games = $duos->matches->valueInt; $squads_games = $squads->matches->valueInt; $solo_kills = $solo->kills->valueInt; $duos_kills = $duos->kills->valueInt; $squads_kills = $squads->kills->valueInt;
I have included some examples of getting certain stats values, but there are plenty more. To view an example of the stats.json file (api call response) see the spoiler below, you can see how the iteration through the arrays is done.
To easily and automatically tweet out your last matches finish place and kills with the Twitter api see this post.
{ "accountId": "c2ba46b3-83d2-4ef9-ac85-f3ba64bd4033", "platformId": 3, "platformName": "pc", "platformNameLong": "PC", "epicUserHandle": "PLAYERSUSERNAME", "stats": { "p2": { "score": { "label": "Score", "field": "Score", "category": "General", "valueInt": 69346, "value": "69346", "rank": 7850, "percentile": 6.0, "displayValue": "69,346" }, "top1": { "label": "Wins", "field": "Top1", "category": "Tops", "valueInt": 43, "value": "43", "rank": 5066, "percentile": 6.0, "displayValue": "43" }, "top3": { "label": "Top 3", "field": "Top3", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top5": { "label": "Top 5", "field": "Top5", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top6": { "label": "Top 6", "field": "Top6", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top10": { "label": "Top 10", "field": "Top10", "category": "Tops", "valueInt": 188, "value": "188", "rank": 2818, "displayValue": "188" }, "top12": { "label": "Top 12", "field": "Top12", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top25": { "label": "Top 25", "field": "Top25", "category": "Tops", "valueInt": 339, "value": "339", "rank": 2676, "percentile": 0.3, "displayValue": "339" }, "kd": { "label": "K/d", "field": "KD", "category": "General", "valueDec": 2.68, "value": "2.68", "rank": 37986, "percentile": 10.0, "displayValue": "2.68" }, "winRatio": { "label": "Win %", "field": "WinRatio", "category": "General", "valueDec": 5.2, "value": "5.2", "rank": 52961, "percentile": 26.0, "displayValue": "5.20" }, "matches": { "label": "Matches", "field": "Matches", "category": "General", "valueInt": 831, "value": "831", "rank": 4235, "percentile": 1.8, "displayValue": "831" }, "kills": { "label": "Kills", "field": "Kills", "category": "General", "valueInt": 2113, "value": "2113", "rank": 2524, "percentile": 1.1, "displayValue": "2,113" }, "minutesPlayed": { "label": "Time Played", "field": "MinutesPlayed", "category": "General", "valueInt": 7085, "value": "7085", "rank": 2971, "percentile": 1.9, "displayValue": "4d 22h 5m " }, "kpm": { "label": "Kills Per Min", "field": "KPM", "category": "General", "valueDec": 0.3, "value": "0.3", "rank": 61034, "percentile": 12.0, "displayValue": "0.30" }, "kpg": { "label": "Kills Per Match", "field": "KPG", "category": "General", "valueDec": 2.54, "value": "2.54", "rank": 36830, "percentile": 9.0, "displayValue": "2.54" }, "avgTimePlayed": { "label": "Avg Match Time", "field": "AvgTimePlayed", "category": "General", "valueDec": 511.55, "value": "511.55", "rank": 85597, "percentile": 29.0, "displayValue": "8m 31s" }, "scorePerMatch": { "label": "Score per Match", "field": "ScorePerMatch", "category": "General", "valueDec": 83.45, "value": "83.45", "rank": 195877, "percentile": 60.0, "displayValue": "83.45" }, "scorePerMin": { "label": "Score per Minute", "field": "ScorePerMin", "category": "General", "valueDec": 9.79, "value": "9.79", "rank": 235292, "percentile": 66.0, "displayValue": "9.79" } }, "p10": { "score": { "label": "Score", "field": "Score", "category": "General", "valueInt": 84482, "value": "84482", "rank": 6466, "percentile": 3.5, "displayValue": "84,482" }, "top1": { "label": "Wins", "field": "Top1", "category": "Tops", "valueInt": 65, "value": "65", "rank": 4945, "percentile": 2.9, "displayValue": "65" }, "top3": { "label": "Top 3", "field": "Top3", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top5": { "label": "Top 5", "field": "Top5", "category": "Tops", "valueInt": 125, "value": "125", "rank": 7512, "percentile": 0.8, "displayValue": "125" }, "top6": { "label": "Top 6", "field": "Top6", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top10": { "label": "Top 10", "field": "Top10", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top12": { "label": "Top 12", "field": "Top12", "category": "Tops", "valueInt": 217, "value": "217", "rank": 7414, "percentile": 0.8, "displayValue": "217" }, "top25": { "label": "Top 25", "field": "Top25", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "kd": { "label": "K/d", "field": "KD", "category": "General", "valueDec": 2.25, "value": "2.25", "rank": 50709, "percentile": 16.0, "displayValue": "2.25" }, "winRatio": { "label": "Win %", "field": "WinRatio", "category": "General", "valueDec": 10.7, "value": "10.7", "rank": 26727, "percentile": 10.0, "displayValue": "10.70" }, "matches": { "label": "Matches", "field": "Matches", "category": "General", "valueInt": 607, "value": "607", "rank": 10376, "percentile": 4.6, "displayValue": "607" }, "kills": { "label": "Kills", "field": "Kills", "category": "General", "valueInt": 1222, "value": "1222", "rank": 10219, "percentile": 4.0, "displayValue": "1,222" }, "minutesPlayed": { "label": "Time Played", "field": "MinutesPlayed", "category": "General", "valueInt": 5057, "value": "5057", "rank": 9433, "percentile": 4.5, "displayValue": "3d 12h 17m " }, "kpm": { "label": "Kills Per Min", "field": "KPM", "category": "General", "valueDec": 0.24, "value": "0.24", "rank": 74595, "percentile": 23.0, "displayValue": "0.24" }, "kpg": { "label": "Kills Per Match", "field": "KPG", "category": "General", "valueDec": 2.01, "value": "2.01", "rank": 56530, "percentile": 18.0, "displayValue": "2.01" }, "avgTimePlayed": { "label": "Avg Match Time", "field": "AvgTimePlayed", "category": "General", "valueDec": 499.87, "value": "499.87", "rank": 94627, "percentile": 32.0, "displayValue": "8m 19s" }, "scorePerMatch": { "label": "Score per Match", "field": "ScorePerMatch", "category": "General", "valueDec": 139.18, "value": "139.18", "rank": 105527, "percentile": 32.0, "displayValue": "139.18" }, "scorePerMin": { "label": "Score per Minute", "field": "ScorePerMin", "category": "General", "valueDec": 16.71, "value": "16.71", "rank": 152640, "percentile": 43.0, "displayValue": "16.71" } }, "p9": { "score": { "label": "Score", "field": "Score", "category": "General", "valueInt": 77970, "value": "77970", "rank": 30583, "percentile": 4.2, "displayValue": "77,970" }, "top1": { "label": "Wins", "field": "Top1", "category": "Tops", "valueInt": 89, "value": "89", "rank": 13312, "percentile": 1.7, "displayValue": "89" }, "top3": { "label": "Top 3", "field": "Top3", "category": "Tops", "valueInt": 151, "value": "151", "rank": 16297, "percentile": 1.6, "displayValue": "151" }, "top5": { "label": "Top 5", "field": "Top5", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top6": { "label": "Top 6", "field": "Top6", "category": "Tops", "valueInt": 203, "value": "203", "rank": 20328, "percentile": 2.0, "displayValue": "203" }, "top10": { "label": "Top 10", "field": "Top10", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top12": { "label": "Top 12", "field": "Top12", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "top25": { "label": "Top 25", "field": "Top25", "category": "Tops", "valueInt": 0, "value": "0", "rank": 1, "displayValue": "0" }, "kd": { "label": "K/d", "field": "KD", "category": "General", "valueDec": 2.64, "value": "2.64", "rank": 35604, "percentile": 11.0, "displayValue": "2.64" }, "winRatio": { "label": "Win %", "field": "WinRatio", "category": "General", "valueDec": 15.9, "value": "15.9", "rank": 23615, "percentile": 4.0, "displayValue": "15.90" }, "matches": { "label": "Matches", "field": "Matches", "category": "General", "valueInt": 560, "value": "560", "rank": 31949, "percentile": 6.0, "displayValue": "560" }, "kills": { "label": "Kills", "field": "Kills", "category": "General", "valueInt": 1243, "value": "1243", "rank": 20724, "percentile": 3.8, "displayValue": "1,243" }, "minutesPlayed": { "label": "Time Played", "field": "MinutesPlayed", "category": "General", "valueInt": 5375, "value": "5375", "rank": 27160, "percentile": 3.9, "displayValue": "3d 17h 35m " }, "kpm": { "label": "Kills Per Min", "field": "KPM", "category": "General", "valueDec": 0.23, "value": "0.23", "rank": 62800, "percentile": 26.0, "displayValue": "0.23" }, "kpg": { "label": "Kills Per Match", "field": "KPG", "category": "General", "valueDec": 2.22, "value": "2.22", "rank": 41551, "percentile": 14.0, "displayValue": "2.22" }, "avgTimePlayed": { "label": "Avg Match Time", "field": "AvgTimePlayed", "category": "General", "valueDec": 575.89, "value": "575.89", "rank": 68833, "percentile": 15.0, "displayValue": "9m 35s" }, "scorePerMatch": { "label": "Score per Match", "field": "ScorePerMatch", "category": "General", "valueDec": 139.23, "value": "139.23", "rank": 142519, "percentile": 32.0, "displayValue": "139.23" }, "scorePerMin": { "label": "Score per Minute", "field": "ScorePerMin", "category": "General", "valueDec": 14.51, "value": "14.51", "rank": 192803, "percentile": 50.0, "displayValue": "14.51" } } }, "lifeTimeStats": [ { "key": "Top 3", "value": "188" }, { "key": "Top 5s", "value": "125" }, { "key": "Top 3s", "value": "151" }, { "key": "Top 6s", "value": "203" }, { "key": "Top 12s", "value": "217" }, { "key": "Top 25s", "value": "339" }, { "key": "Score", "value": "231,798" }, { "key": "Matches Played", "value": "1998" }, { "key": "Wins", "value": "197" }, { "key": "Win%", "value": "10%" }, { "key": "Kills", "value": "4578" }, { "key": "K/d", "value": "2.54" }, { "key": "Kills Per Min", "value": "0.3" }, { "key": "Time Played", "value": "12d 3h 57m " }, { "key": "Avg Survival Time", "value": "8m 46s" } ] }
That is the basics on how to use the Fortnite tracker api with PHP.