Giter VIP home page Giter VIP logo

mojangapi's Introduction

MojangAPI

A easy-to-use PHP class for accessing official Mojang's API

Installation

You only need to download this file: mojang-api.class.php

Usage

See an usage of this class in example.php file. To see all methods available, see the MojangAPI interface: mojang-api.interface.php (not needed in your project).

Example

// Require API
require 'mojang-api.class.php';

// Get UUID from username
$uuid = MojangAPI::getUuid('MTC');
echo 'UUID: <b>' . $uuid . '</b><br>';

// Get his name history
$history = MojangAPI::getNameHistory($uuid);
echo 'First username: <b>' . reset($history)['name'] . '</b><br>';

// Print player's head
$img = '<img src="' . MojangAPI::embedImage(MojangAPI::getPlayerHead($uuid)) . '" alt="Head of MTC">';
echo 'Skin:<br>' . $img . '<br>';

// Query a server
$query = MojangAPI::query('play.onecraft.fr', 25565);
if ($query) echo 'There is ' . $query['players'] . ' players online out of ' . $query['maxplayers'] . '<br>';
else echo 'Server is offline.<br>';

Result

Preview

mojangapi's People

Contributors

minethecube avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mojangapi's Issues

Getting false results on an open server

I am getting false results on a server that I tried pinging. The webpage just returns false. It is the Example.php code that I changed the server adress in. Please help.

Doesn't work anymore at all

Does your API still work? Can't get it to do so.

This is my code:

<?php
    // Require API
    require 'mojangApi.php';

    // Get UUID from username
    $uuid = MojangAPI::getUuid('MTC');
    echo 'UUID: <b>' . $uuid . '</b><br>';

    // Get his name history
    $history = MojangAPI::getNameHistory($uuid);
    echo 'First username: <b>'.reset($history)['name'].'</b><br>';

    // Print player's head
    $img = '<img src="' . MojangAPI::embedImage(MojangAPI::getPlayerHead($uuid)) . '" alt="Head of MTC">';
    echo 'Skin:<br>' . $img . '<br>';

?>

This is how the website looks like when it's loaded:
image

I read that warning but when I do:

if(MojangAPI::getUuid('Player')

it always returns false.

Cannot get any info from players

Using your class, I can check server status and icon. However I cannot seem to get any UUIDs, usernames or such from players. Have I done something wrong or is it somehow outdated or not working? I'd love to use your class if it ends up working for me, due to its ease of use compared to what I have to do otherwise.

Namespacing

Ever heard of namespacing? Jesus, this code reminds me of 2005

The Mojang authentication system does not work.

In the code I write my data from my account Mojang:
// Require API
require 'mojang-api.class.php';
$result = MojangAPI::authenticate('[email protected]', 'mypassword');

if ($result) {
echo 'Welcome ' . $result['name'] . ', your UUID is: ' . $result['id'];
} else {
echo 'Sorry, authentication failed.. :(';
}

And the result shows the error message. (Here I deleted my personal data for anyone to see, but in the code I wrote it correctly)

Can't get server players.

Hey! I am trying to get hypixel's players online on my site but it always says that this server is offline :(
<?php require 'MojangAPI/mojang-api.class.php'; $query = MojangAPI::query('eu.hypixel.net', 25565); if ($query) echo '<a href="#" style="color: green;">Hypixel online' . $query['players'] . '/' . $query['maxplayers']. '</a>'; else echo '<a href="#" style="color: red;">Hypixel is offline.</a>' ?>
P.S. your example won't work too.

Not working

Using Apache 2.4.17, PHP 5.6.15
I'm receiving this:
screen
While using the example.

Erreur lors de l'utilisation de curl

A priori vous êtes français moi aussi, ca sera plus simple :) C'est dommage je suis allé sur votre serveur vous n'y étiez pas :(
Bref j'ai trouver un script de test que vous avez partagé dans une autre issue, et j'ai un problème un peu différent :s

<?php

error_reporting(E_ALL);
ini_set('display_errors', true);

$url = 'https://api.mojang.com/users/profiles/minecraft/MTC';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
curl_setopt($ch, CURLOPT_TIMEOUT, 5);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

$output = curl_exec($ch);
var_dump($output);

var_dump(curl_error($ch), curl_errno($ch));

curl_close($ch);

Le script retourne tout çà :

string(555) "
ERROR
The request could not be satisfied.
Request blocked. 
Generated by cloudfront (CloudFront)
Request ID: CjhzWljAre53I1sRh6vNcl92Axbjfi8droxGU_D8qXgzzyuQBTw_eA==
" string(0) "" int(0)

J'héberge moi même le site web sur un serveur dedié.
Il tourne sur Debian 8.
J'ai installer l’extension php5-curl.

Sa fait une bonne journée que je cherche un moyen pour résoudre ce problème mais rien a faire.
J'ai essayé un file_get_contents(); qui du-coup marche très bien en local, mais sur le site rien a faire çà ne marche pas. Puis plein d'autres petites solutions sur différents forum, vous m’enlèverez une épine du pied si vous me trouvez le problème ;)

Cordialement,
DURAND LUCAS.

Cannot find my user

Hello,

I downloaded the api file to make an admin panel of my server, but impossible to retrieve information from it.
I did import my file, but 0 results from any functions.

Can you help me ?

@section('content') <?php require app_path().'/mojang-api.class.php'; ?> <div class="content"> <?php $name = MojangAPI::getUsername('6ce86bff-695f-4a5b-b6c5-7e924975f74b'); echo 'Name: <b>' . $name . '</b><br>'; ?> </div> @endsection
image

Future Proof?

In mojang-api.class.php line 178:
The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.