From c8daaed9babbb641bcf3de9b4a5307f1abd20b58 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 11 Aug 2018 05:55:37 +0300 Subject: [PATCH] Fix Leaderboard error 500 Added user in_app_id Added new get request for leaderboard users Changed build versions Fixed leaderboard error 500 --- src/Auth.php | 14 ++++++++++---- src/FortniteClient.php | 8 ++++---- src/Leaderboard.php | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index eb1aeef..495ecfe 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -7,6 +7,7 @@ class Auth { private $access_token; + private $in_app_id; private $refresh_token; private $account_id; private $expires_in; @@ -24,14 +25,15 @@ class Auth { * @param string $account_id Unreal Engine account id * @param string $expires_in OAuth2 token expiration time */ - private function __construct($access_token, $refresh_token, $account_id, $expires_in) { + private function __construct($access_token, $in_app_id, $refresh_token, $account_id, $expires_in) { $this->access_token = $access_token; + $this->in_app_id = $in_app_id; $this->refresh_token = $refresh_token; $this->account_id = $account_id; $this->expires_in = $expires_in; $this->profile = new Profile($this->access_token, $this->account_id); $this->account = new Account($this->access_token); - $this->leaderboard = new Leaderboard($this->access_token, $this->account); + $this->leaderboard = new Leaderboard($this->access_token, $this->in_app_id, $this->account); $this->store = new Store($this->access_token); $this->news = new News($this->access_token); $this->status = new Status($this->access_token); @@ -80,7 +82,7 @@ public static function login($email, $password) { throw new \Exception($data->errorMessage); } - return new self($data->access_token, $data->refresh_token, $data->account_id, $data->expires_in); + return new self($data->access_token, $data->in_app_id, $data->refresh_token, $data->account_id, $data->expires_in); } /** @@ -100,7 +102,7 @@ public static function refresh($refresh_token) { throw new \Exception($data->errorMessage); } - return new self($data->access_token, $data->refresh_token, $data->account_id, $data->expires_in); + return new self($data->access_token, $data->in_app_id, $data->refresh_token, $data->account_id, $data->expires_in); } /** @@ -126,4 +128,8 @@ public function expiresIn() { public function accessToken() { return $this->access_token; } + + public function inAppId() { + return $this->in_app_id; + } } \ No newline at end of file diff --git a/src/FortniteClient.php b/src/FortniteClient.php index c6a71ee..cbe2e71 100644 --- a/src/FortniteClient.php +++ b/src/FortniteClient.php @@ -51,7 +51,7 @@ public static function sendUnrealClientGetRequest($endpoint, $authorization = se try { $response = $client->get($endpoint, [ 'headers' => [ - 'User-Agent' => 'game=UELauncher, engine=UE4, build=7.3.1-3881656+++Portal+Release-Live', + 'User-Agent' => 'game=UELauncher, engine=UE4, build=7.14.2-4231683+++Portal+Release-Live', 'Authorization' => (!$oauth) ? 'basic ' . $authorization : 'bearer ' . $authorization ] ]); @@ -77,7 +77,7 @@ public static function sendUnrealClientPostRequest($endpoint, $params = null, $a $response = $client->post($endpoint, [ 'form_params' => $params, 'headers' => [ - 'User-Agent' => 'game=UELauncher, engine=UE4, build=7.3.1-3881656+++Portal+Release-Live', + 'User-Agent' => 'game=UELauncher, engine=UE4, build=7.14.2-4231683+++Portal+Release-Live', 'Authorization' => (!$oauth) ? 'basic ' . $authorization : 'bearer ' . $authorization ] ]); @@ -99,7 +99,7 @@ public static function sendFortniteGetRequest($endpoint, $access_token, $extra_h $client = new Client(); $headers = [ - 'User-Agent' => 'game=Fortnite, engine=UE4, build=++Fortnite+Release-2.5-CL-3889387, netver=3886413', + 'User-Agent' => 'Fortnite/++Fortnite+Release-5.20-CL-4259375 Windows/10.0.17728.1.256.64bit', 'Authorization' => 'bearer ' . $access_token ]; @@ -130,7 +130,7 @@ public static function sendFortnitePostRequest($endpoint, $access_token, $params $response = $client->post($endpoint, [ 'json' => $params, 'headers' => [ - 'User-Agent' => 'game=Fortnite, engine=UE4, build=++Fortnite+Release-2.5-CL-3889387, netver=3886413', + 'User-Agent' => 'Fortnite/++Fortnite+Release-5.20-CL-4259375 Windows/10.0.17728.1.256.64bit', 'Authorization' => 'bearer ' . $access_token ] ]); diff --git a/src/Leaderboard.php b/src/Leaderboard.php index c86752c..4a4e713 100644 --- a/src/Leaderboard.php +++ b/src/Leaderboard.php @@ -16,11 +16,14 @@ class Leaderboard { private $access_token; + private $in_app_id; private $account; - public function __construct($access_token, Account $account) + + public function __construct($access_token, $in_app_id, Account $account) { $this->account = $account; + $this->in_app_id = $in_app_id; $this->access_token = $access_token; } @@ -44,9 +47,16 @@ public function get($platform, $type) } try { + $data_cohort = FortniteClient::sendFortniteGetRequest( + FortniteClient::FORTNITE_API . "game/v2/leaderboards/cohort/$this->in_app_id?playlist={$platform}_m0{$type}", + $this->access_token, array('Content-Type: application/json') + ); + + + $data = FortniteClient::sendFortnitePostRequest( FortniteClient::FORTNITE_API . "leaderboards/type/global/stat/br_placetop1_{$platform}_m0{$type}/window/weekly?ownertype=1&itemsPerPage=50", - $this->access_token + $this->access_token, $data_cohort->cohortAccounts ); $entries = $data->entries; @@ -81,4 +91,4 @@ public function get($platform, $type) throw $e; } } -} +} \ No newline at end of file