PHP code example of navarr / minecraft-api

1. Go to this page and download the library: Download navarr/minecraft-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/ */

    

navarr / minecraft-api example snippets



    // composer autoload call
    
    use Navarr\MinecraftAPI\MinecraftAPI;
    use Navarr\MinecraftAPI\Exception\BadLoginException;
    use Navarr\MinecraftAPI\Exception\MigrationException;
    use Navarr\MinecraftAPI\Exception\BasicException;
    
    try {
        $minecraftApi = new MinecraftAPI($username, $password);
    } catch (BadLoginException $e) {
        // Invalid Credentials
    } catch (MigrationException $e) {
        // User tried to login with their minecraft name instead of their mojang account handle (and have migrated)
    } catch (BasicException $e) {
        // The account is a "basic" Minecraft account.  They have not purchased Minecraft.
    }
    
    $minecraftName = $minecraftApi->username;
    $accessToken = $minecraftApi->accessToken;
    $uuid = $minecraftApi->minecraftID;