To get your or another Fortnite players kills, K/D, matches played, wins, kills per match, time played, win ratio and more by using the api with 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), players username (line 2) and your api key (line 8)
$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 Fortnite data using curl and save it into a .json file to save excess api calling.
Now lets read the saved data and echo out some values
$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_kills = $solo->kills->valueInt; $duos_kills = $duos->kills->valueInt; $squads_kills = $squads->kills->valueInt; $solo_mins_played = $solo->minutesPlayed->valueInt; $duos_mins_played = $duos->minutesPlayed->valueInt; $squads_mins_played = $squads->minutesPlayed->valueInt; $solo_win_ratio = $solo->winRatio->valueDec; $duos_win_ratio = $duos->winRatio->valueDec; $squads_win_ratio = $squads->winRatio->valueDec; $solo_kpm = $solo->kpm->valueDec; $duos_kpm = $duos->kpm->valueDec; $squads_kpm = $squads->kpm->valueDec; //echo out for solo echo "Solo stats | Matches: $solo_matches Wins: $solo_wins Kills: $solo_kills K/d: $solo_kd Minutesplayed: $solo_mins_played Win ratio: $solo_win_ratio Kills per match: $solo_kpm"; //echo out for squads echo "Squads stats | Matches: $squads_matches Wins: $squads_wins Kills: $squads_kills K/d: $squads_kd Minutes played: $squads_mins_played Win ratio: $squads_win_ratio Kills per match: $squads_kpm";
Here you can see how i assigned variables to parts of the returned data from the Fortnite api call. To view the json file (api call response) see the spoiler below, you can see how the iteration through the arrays is done.