{"id":359,"date":"2020-02-12T23:10:35","date_gmt":"2020-02-13T05:10:35","guid":{"rendered":"https:\/\/justinstolpe.com\/blog\/?p=359"},"modified":"2021-01-26T22:07:28","modified_gmt":"2021-01-27T04:07:28","slug":"create-a-fortnite-player-stats-website","status":"publish","type":"post","link":"https:\/\/justinstolpe.com\/blog\/2020\/02\/12\/create-a-fortnite-player-stats-website\/","title":{"rendered":"Create a Fortnite Player Stats Website"},"content":{"rendered":"<p><center><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/eWyKJUqzNC8\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" data-mce-type=\"bookmark\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/center><span class=\"style-scope yt-formatted-string\" dir=\"auto\">In this post we are going to use the Fortnite Tracker API to get and display stats for any player. By hitting the player stats endpoint with a platform (pc, xbox, playstation), and the name of the player, we can get back their lifetime, solo, duo, and squad stats. Once we have our data, we can style it up and make it look like a Fortnite website using HTML, CSS, and PHP!<br \/>\n<\/span><\/p>\n<h3><strong>Step 1: Connect to the Fortnite API<br \/>\n<\/strong><\/h3>\n<p>First thing we need is an API key. This will be passed along with each call we make to any of the API endpoints.<\/p>\n<ol>\n<li>Login here <a href=\"https:\/\/fortnitetracker.com\/site-api\" target=\"_blank\" rel=\"noopener\">https:\/\/fortnitetracker.com\/site-api<\/a><\/li>\n<li>Click on\u00a0 <a class=\"btn btn-default btn-sm\" href=\"https:\/\/tracker.gg\/developers\/apps\">Manage or Create API Keys<\/a><\/li>\n<li>Create an Application<\/li>\n<li>At the bottom of your applications details page you will see your API Key.<\/li>\n<\/ol>\n<p>We are going to be using the player stats endpoint to retrieve the stats on a player. The endpoint requires a platform (pc, xb1, psn), and an epic nickname.<\/p>\n<p>Endpoint <strong>https:\/\/api.fortnitetracker.com\/v1\/profile\/{platform}\/{epic-nickname}<\/strong><\/p>\n<p>Now we will write a function to make it easy to get player stats. Using curl, we will pass along our endpoint and the correct parameters (platform, epic nickname, api key)<\/p>\n<pre>\r\n\/\/ place your api key here define( 'FN_API_KEY', 'YOUR-API-KEY-HERE' ); \r\n\r\n\/** \r\n * Get player stats from the fortnite api \r\n * \r\n * @param String $platform the epicNickname is on (pc, xb1, psn) \r\n * @param String $epicNickname name of the player \r\n * \r\n * @return Array \r\n *\/ \r\nfunction getPlayerStats( $platform, $epicNickname ) { \/\/ api endpoint with the platform and epicNickname \r\n\t$apiUrlPlayerStatsEndpoint = 'https:\/\/api.fortnitetracker.com\/v1\/profile\/' . $platform . '\/' . $epicNickname; \r\n\r\n\t\/\/ open curl call \r\n\t$ch = curl_init(); \r\n\r\n\t\/\/ specify our api endpoint \r\n\tcurl_setopt( $ch, CURLOPT_URL, $apiUrlPlayerStatsEndpoint ); \r\n\r\n\t\/\/ pass along our api key as TRN-API-Key in the headers \r\n\tcurl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'TRN-Api-Key:' . FN_API_KEY ) ); \r\n\r\n\t\/\/ more curl options curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); \r\n\tcurl_setopt( $ch, CURLOPT_HEADER, FALSE ); \r\n\tcurl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); \r\n\r\n\t\/\/ get response from api and close curl \r\n\t$response = curl_exec( $ch ); \r\n\r\n\tcurl_close( $ch ); \r\n\r\n\t\/\/ return api response as a php array \r\n\treturn json_decode( $response, true ); \r\n}\r\n<\/pre>\n<h3><strong>Step 2: Style It Up<br \/>\n<\/strong><\/h3>\n<p>Once we have our data. We can go ahead and start giving it a nice Fortnite look and feel. If we want our player stats to feel like Fortnite, we need the correct font face. Here is the font face I am using.<\/p>\n<pre>@font-face { \r\n    font-family: 'Fortnite'; \r\n    src: url( 'BurbankBigCondensed-Bold.otf' ); \r\n}<\/pre>\n<h3><strong>Fortnite Player Stats Website<br \/>\n<\/strong><\/h3>\n<p><a href=\"https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-362\" src=\"https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps.png\" alt=\"Fortnite player stats\" width=\"2559\" height=\"1375\" srcset=\"https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps.png 2559w, https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps-300x161.png 300w, https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps-768x413.png 768w, https:\/\/justinstolpe.com\/blog\/wp-content\/uploads\/2020\/02\/fnps-1024x550.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<p>Put everything together and we get our own Fortnite player stats website! I\u00a0 highlighted the main part which is connecting to the API and the custom Fortnite font face. The rest is just simple HTML\/CSS and full code is up on GitHub!<\/p>\n<p style=\"text-align: center;\"><strong>Links<\/strong><\/p>\n<p><a href=\"https:\/\/justinstolpe.com\/blog_code\/fortnite_player_stats\/\" target=\"_blank\" rel=\"noopener\"><strong>Live Demo<\/strong><\/a><\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=eWyKJUqzNC8\" target=\"_blank\" rel=\"noopener\"><strong>YouTube Video<\/strong><\/a><\/p>\n<p><strong><a href=\"https:\/\/github.com\/jstolpe\/blog_code\/tree\/master\/fortnite_item_shop\" target=\"_blank\" rel=\"noopener\">Code on GitHub<\/a><\/strong><\/p>\n<p>That is going to do it for this post! Leave any comments\/questions\/concerns below and thanks for stopping by the blog!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ufeffIn this post we are going to use the Fortnite Tracker API to get and display stats for any player. By hitting the player stats endpoint with a platform (pc, xbox, playstation), and the name of the player, we can get back their lifetime, solo, duo, and squad stats. Once we have our data, we &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/justinstolpe.com\/blog\/2020\/02\/12\/create-a-fortnite-player-stats-website\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Create a Fortnite Player Stats Website&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":367,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,11,10,9,1],"tags":[7,15,13,8],"class_list":["post-359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-css","category-html","category-php","category-uncategorized","tag-coding","tag-css","tag-html","tag-php"],"_links":{"self":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/comments?post=359"}],"version-history":[{"count":23,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions\/420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/media\/367"}],"wp:attachment":[{"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/media?parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/categories?post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justinstolpe.com\/blog\/wp-json\/wp\/v2\/tags?post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}