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 //wins data $solo_wins = $solo->top1->valueInt; $duos_wins = $duos->top1->valueInt; $squads_wins = $squads->top1->valueInt; //matches played data $solo_matches = $solo->matches->valueInt; $duos_matches = $duos->matches->valueInt; $squads_matches = $squads->matches->valueInt; //k/d data $solo_kd = $solo->kd->valueDec; $duos_kd = $duos->kd->valueDec; $squads_kd = $squads->kd->valueDec; //kills data $solo_kills = $solo->kills->valueInt; $duos_kills = $duos->kills->valueInt; $squads_kills = $squads->kills->valueInt; //minutes played data $solo_mins_played = $solo->minutesPlayed->valueInt; $duos_mins_played = $duos->minutesPlayed->valueInt; $squads_mins_played = $squads->minutesPlayed->valueInt; //win ration data $solo_win_ratio = $solo->winRatio->valueDec; $duos_win_ratio = $duos->winRatio->valueDec; $squads_win_ratio = $squads->winRatio->valueDec; //kills per match $solo_kpm = $solo->kpm->valueDec; $duos_kpm = $duos->kpm->valueDec; $squads_kpm = $squads->kpm->valueDec; //echo out variables example for solo stats 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.
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Using FTP and PHP to get an array of file details such as size and…
Creating and using Laravel form requests to create cleaner code, separation and reusability for your…
Improving the default Laravel login and register views in such a simple manner but making…
Laravel validation for checking if a field value exists in the database. The validation rule…