Skip to content
This repository has been archived by the owner on Feb 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #36 from Krokit/master
Browse files Browse the repository at this point in the history
Fix Leaderboard error 500
  • Loading branch information
Tustin authored Aug 11, 2018
2 parents 8cc587f + c8daaed commit 6ccf0b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Auth {
private $access_token;
private $in_app_id;
private $refresh_token;
private $account_id;
private $expires_in;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -126,4 +128,8 @@ public function expiresIn() {
public function accessToken() {
return $this->access_token;
}

public function inAppId() {
return $this->in_app_id;
}
}
8 changes: 4 additions & 4 deletions src/FortniteClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
]);
Expand All @@ -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
]
]);
Expand All @@ -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
];

Expand Down Expand Up @@ -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
]
]);
Expand Down
16 changes: 13 additions & 3 deletions src/Leaderboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;

Expand Down Expand Up @@ -81,4 +91,4 @@ public function get($platform, $type)
throw $e;
}
}
}
}

0 comments on commit 6ccf0b2

Please sign in to comment.