PHP code example of trackbasenet / dev-api

1. Go to this page and download the library: Download trackbasenet/dev-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trackbasenet / dev-api example snippets






$options = [
	'game' => 'et'
];

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak, $options);

/*
 * Available options, specifically for this method:
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->ranklist($options);

/*
 * Available options, specifically for this method:
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->toplist($options);

/*
 * Available options, specifically for this method:
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->clanRanklist($options);

/*
 * Available options, specifically for this method:
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->clanToplist($options);

/*
 * Available options, specifically for this method:
 * pid: any integer greater than 0 that corresponds to a player's ID
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'pid' => 1,
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->playerInfo($options);

/*
 * Available options, specifically for this method:
 * pid: any integer greater than 0 that corresponds to a player's ID
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'pid' => 1,
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->playerServers($options);

/*
 * Available options, specifically for this method:
 * pid: any integer greater than 0 that corresponds to a player's ID
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'pid' => 1,
	'order' => 'asc',
	'limit' => 10,
	'start' => 1
];

$api->playerSessions($options);

/*
 * Available options, specifically for this method:
 * cid: any integer greater than 0 that corresponds to a clan's ID
 * order: 'asc' or 'desc'
 */

// Following options are default and do not need to be supplied by default
$options = [
	'cid' => 1,
	'order' => 'asc',
];

$api->clanInfo($options);

/*
 * Available options, specifically for this method:
 * sid: any integer greater than 0 that corresponds to a server's ID
 * order-by: one of the following: ['xp', 'rate', 'rating', 'ping', 'class', 'kills', 'deaths', 'playername']
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'sid' => 1,
	'order-by' => 'rate',
	'order' => 'desc',
	'limit' => 10,
	'start' => 1
];

$api->serverInfo($options);

/*
 * Available options, specifically for this method:
 * sid: any integer greater than 0 that corresponds to a server's ID
 * order-by: 'time'
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'sid' => 1,
	'order-by' => 'time',
	'order' => 'desc',
	'limit' => 10,
	'start' => 1
];

$api->serverSessions($options);

/*
 * Available options, specifically for this method:
 * sid: any integer greater than 0 that corresponds to a server's ID
 * order-by: one of the following: ['playername', 'rate', 'rating', 'time', 'ratetime', 'lastseen']
 * order: 'asc' or 'desc'
 * limit: any integer between 1 and 50
 * start: any integer greater than 0, useful for pagination
 */

// Following options are default and do not need to be supplied by default
$options = [
	'sid' => 1,
	'order-by' => 'rate',
	'order' => 'desc',
	'limit' => 10,
	'start' => 1
];

$api->serverUsage($options);

/*
 * Available options, specifically for this method:
 * uid: any integer greater than 0 that corresponds to a user's ID
 * request: binary request number that translates to the information that should be received. For more information, please check the documentation / your app on our developers platform
 */

// Following options are default and do not need to be supplied by default
$options = [
	'uid' => 0,
	'request' => 0
];

$api->userInfo($options);

// This method is a shortcut for the ->userInfo() method and receives the $user_id and $request integers as its arguments
$api->getUser($user_id, $request);

// This method can be called when you want to connect a user to your app. It returns a redirection header to our developers platform.
$api->connectUser();

// This method needs to be called on the URI that has been submitted as your "Server URL" in your app settings. It holds the logic for fetching a user in the correct way. It // or return the user ID itself. If so, you might want to catch this methods return inside a new variable ($possible_new_user_id)
});

$topTenPlayers_count = $api->ranklist()->countResults();

$topPlayer = $api->ranklist()->firstResult();

$topTenPlayers = $api->ranklist()->getResults();

$requestStatusCode = $api->ranklist()->getStatusCode();

$requestMessage = $api->ranklist()->getMessage();

$requestErrorMessage = $api->ranklist()->getError();

$requestErrorCode = $api->ranklist()->getErrorCode();

$hasErrors = $api->ranklist()->hasErrors();

if ($hasErrors) {
	// Show errors
}

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak, ['game' => 'et']);

$results = $api->ranklist(['order' => 'asc', 'limit' => 10, 'start' => 1])->getResults();

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

$results = $api->ranklist()->getResults();

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

$results = $api->serverSessions(['sid' => 1234, 'limit' => 5])->getResults();

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

$player = $api->playerInfo(['pid' => 1234])->firstResult();

echo "Hello, {$player->playername_html}!";

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

$api->collectNewUser($returnToken, function ($user_id) use ($database) {
	$database->insertRow('users_table', ['trackbase_userid' => $user_id]);
});

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

// Get the user's username
$api->userInfo([
	'uid' => $user_id,
	'request' => 1
]);

$api = new \TrackBaseNet\TrackBaseApi($app_id, $relation_token, $_aak);

// Get the user's username
$api->getUser($user_id, 1);