greenhollowtech/ght-mojang-api-client-bundle

GHT Mojang API 客户端套餐

1.1.0 2016-08-08 01:03 UTC

This package is auto-updated.

Last update: 2024-08-26 08:19:26 UTC


README

本套餐提供 GHT Mojang API 客户端,作为 Symfony 中的服务。

安装

获取 Composer 包

使用 Composer 安装,运行 composer require greenhollowtech/ght-mojang-api-client-bundle

将 GHTMojangApiClientBundle 添加到您的 Symfony 应用程序

// app/AppKernel.php

    public function registerBundles()
    {
        return array(
            // ...
            new GHT\MojangApiClientBundle\GHTMojangApiClientBundle(),
            // ...
        );
    }

使用方法

未认证 API 方法

$mojangClient = $this->get('ght_mojang_api_client');

// Get all names a user has ever used
$names = $mojangClient->getNames($uuid);

// Get profile data for a UUID
$profile = $mojangClient->getProfile($uuid);

// Get the UUID for the user currently or in the past using a given name
$profile = $mojangClient->getProfileForName('SomeDude');
$profile = $mojangClient->getProfileForName('SomeDude', new \DateTime('-1 month'));

// Get the UUIDs (and possibly other limited information) of a list of names
$profiles = $mojangClient->getProfilesForNames(array('SomeDude', 'SomeOtherDude'));

// Get Mojang statistics
$statistics = $mojangClient->getStatistics();
$metrics = array('item_sold_minecraft', 'item_sold_scrolls');
$statistics = $mojangClient->getStatistics($metrics);
$splitByMetric = true;
$statistics = $mojangClient->getStatistics($metrics, $splitByMetric);

// Get statuses for all services
$statuses = $mojangClient->getStatus();
$minecraftStatus = $statuses['minecraft.net'];

// Check a URL if the server is blocked
$serverIsBlocked = $mojangClient->isServerBlocked('https://some.test.myservername.com');

认证方法

所有这些方法将返回 true 或 false。如果失败,可以访问捕获的错误消息。

// Authenticate the client
if (!$mojangClient->authenticate($email, $password)) {
    // authentication failed
    echo $mojangClient->getLastError();
}

// Validate the current credentials
if (!$mojangClient->validate()) {
    // authentication is invalid
    echo $mojangClient->getLastError();
}

// Authenticating with a game as the agent provides better credentials
$mojangClient->authenticate($email, $password, 'Minecraft');

// Refreshes the API token transported in the client
$mojangClient->refresh();

// End the authenticated session by invalidating the token
$mojangClient->invalidate();

// End the authenticated session using the login name and password
$mojangClient->signOut($email, $password);

认证 API 方法

所有这些方法都需要客户端先进行认证。

// Authenticate the client
if (!$mojangClient->authenticate($email, $password, 'Minecraft')) {
    if (!$mojangClient->authenticate($email, $password)) {
        // authentication failed, do something!
    }
}

// Change a skin
if (!$mojangClient->changeSkin($uuid, $url, 'slim')) {
    echo sprintf('Could not change skin! (%s)', $mojangClient->getLastError());
}

// Get the current user's information
$userInfo = $mojangClient->getUserInformation();

// Reset the user's skin
if (!$mojangClient->resetSkin($uuid)) {
    echo sprintf('Could not reset skin! (%s)', $mojangClient->getLastError());
}

// Upload a skin
if (!$mojangClient->uploadSkin($uuid, '/tmp/skinFile.png', 'slim')) {
    echo sprintf('Could not upload skin! (%s)', $mojangClient->getLastError());
}