PHP code example of xgerhard / destiny-api-wrapper

1. Go to this page and download the library: Download xgerhard/destiny-api-wrapper 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/ */

    

xgerhard / destiny-api-wrapper example snippets


$oDestiny = new Destiny\Client('Bungie-API-key-here');

use Destiny\Client;
use Destiny\Exceptions\PlayerNotFoundException;

try
{
    $oDestiny = new Destiny\Client('Bungie-API-key-here');
    $oPlayer = $oDestiny->searchPlayer('xgerhard');

    echo $oPlayer->membershipId; // 4611686018467322796
    echo $oPlayer->membershipType; // 4
    echo $oPlayer->displayName; // xgerhard#21555

    // There are multiple ways of searching a player
    // Search on all platforms by player username
    $oPlayer = $oDestiny->searchPlayer('xgerhard');

    // Search on specific platform by player username (1 = xbox, 2 = ps, 3 = pc)
    $oPlayer = $oDestiny->searchPlayer('xgerhard', 1);

    // Search by BungieNet uniqueName
    // Set an unique ID here: https://www.bungie.net/en/Profile/Settings/?category=AboutMe
    // Link the platforms you play on here: https://www.bungie.net/en/Profile/Settings/?category=Accounts
    // By using profiles->getCurrent you will receive the platform you played on most recently
    $oPlayer = $oDestiny->searchUser('xgerhard')->profiles->getCurrent();

    // Combination of searchPlayer & searchUser
    // Search by platform username first, if no results search by uniqueName on BungieNet
    $oPlayer = $oDestiny->searchPlayerUser('xgerhard');

    // Search on specific platform only, if no results search by uniqueName on BungieNet
    $oPlayer = $oDestiny->searchPlayerUser('xgerhard', 1);

    // $oPlayer = Destiny\Player
}
catch(PlayerNotFoundException $e)
{
    // If no players could be found
    echo $e->getMessage();
}

use Destiny\Client;
use Destiny\Exceptions\InvalidPlayerParametersException;

try
{
    $oDestiny = new Destiny\Client('Bungie-API-key-here');
    $oPlayer = $oDestiny->loadPlayer([
        'membershipType' => 4,
        'membershipId' => '4611686018467322796',
        'displayName' => 'xgerhard#21555'
    ]);

    // $oPlayer = Destiny\Player
}
catch(InvalidPlayerParametersException $e)
{
    // If 

$oPlayer = $oDestiny->searchPlayer('xgerhard');
$aCharacters = $oPlayer->characters->getAll();

/*
Array
(
    [2305843009301405871] => Destiny\Character Object
        (
            [membershipId] => 4611686018467322796
            [membershipType] => 4
            [characterId] => 2305843009301405871
            ....
        )

    [2305843009301408262] => Destiny\Character Object
        (
            [membershipId] => 4611686018467322796
            [membershipType] => 4
            [characterId] => 2305843009301408262
            ....
        )
)
*/

$oPlayer = $oDestiny->searchPlayer('xgerhard');
$aCharacters = $oPlayer->characters->getCurrent();

/*
Destiny\Character Object
(
    [membershipId] => 4611686018467322796
    [membershipType] => 4
    [characterId] => 2305843009301408262
    [dateLastPlayed] => 2019-06-22T15:43:44Z
    [minutesPlayedThisSession] => 30
    ....
)
*/

$oPlayer = $oDestiny->searchPlayer('xgerhard');

// If I only need the characters data (for example: characterId, dateLastPlayed)
$aCharacters = $oPlayer->characters->fetch([200]);

// If I want to check characters inventory
$oPlayer->characters->fetch([
    200, // Character basic info
    205, // Character equipment
    300, // Item instances
    305 // Item sockets
]);

// Get primary weapon for all characters
foreach($oPlayer->characters->getAll() as $oCharacter)
{
    $oPrimary = $oCharacter->inventory->get('primary');
}

// Or just for the current character
$oPlayer->characters->getCurrent()->inventory->get('primary');

$oPlayer = $oDestiny->searchUser('xgerhard')->profiles->getCurrent();

// Fetch character data, including equipment, item instances, item sockets
$oCurrentCharacter = $oPlayer->characters->getCurrent([200, 205, 300, 305]);

$oPrimary = $oCurrentCharacter->inventory->get('primary', true));

/*
Destiny\EquipmentItem Object
(
    [itemInstanceId] => 6917529067574353832
    [itemHash] => 347366834
    [name] => Ace of Spades
    [bucketTypeHash] => 1498876634
    [light] => 750
    [quantity] => 1
    [perks] => Array
        (
            [0] => Memento Mori
            [1] => Corkscrew Rifling
            [2] => High-Caliber Rounds
            [3] => Firefly
            [4] => Smooth Grip
            [5] => Last Hand
            [6] => Empty Catalyst Socket
        )
)
*/

// $oPrimary = Destiny\EquipmentItem

$aItems = $oCurrentCharacter->inventory->get(['helmet', 'chest']);

/*
Array
(
    [helmet] => Destiny\EquipmentItem Object
        (
            [itemInstanceId] => 6917529088474208321
            [itemHash] => 2124666626
            [name] => Wing Discipline
            [bucketTypeHash] => 3448274439
            [light] => 750
            [quantity] => 1
        )
    [chest] => Destiny\EquipmentItem Object
        (
            [itemInstanceId] => 6917529085963882227
            [itemHash] => 2562470699
            [name] => Tangled Web Plate
            [bucketTypeHash] => 14239492
            [light] => 750
            [quantity] => 1
        )
)
*/

$oManifest = $oDestiny->getManifest();
$oItem = $oManifest->getDefinition('InventoryItem', 3588934839);

/*
stdClass Object
(
    [displayProperties] => stdClass Object
        (
            [description] => "Wings flutter. Beauty distracts. Poison injects. The butterfly's curse extends to your enemies. A short life, shortened further by your hand." —Ada-1
            [name] => Le Monarque
            [icon] => /common/destiny2_content/icons/4b66c583e88a316cc3b0cf017a3e9a7b.jpg
            [hasIcon] => 1
        )
    ....
*/

// $oManifest = Destiny\Manifest

var_dump($oDestiny->updateManifest());
/*
bool(true)
*/