PHP - API Help

Status
This thread has been locked.
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Jack

Retired Moderator
Supreme
Feedback score
11
Posts
1,210
Reactions
1,462
Resources
0
PHP:
<?php

// The username we want to check
$name = "Car";

// Get response from UUID API
$resp = file_get_contents("https://api.mojang.com/users/profiles/minecraft/".$name);

if(!$resp) {
    // Response empty, no account with that username exists
    die("Username does not exist.");
}

// Decode the response (JSON), and get the 'id' (UUID) field
$uuid = json_decode($resp, true)['id'];

// We have the UUID now, can lookup name history
$resp = file_get_contents("https://api.mojang.com/user/profiles/".$uuid."/names");

// Decode the response (JSON) to get the name history
$history = json_decode($resp, true);

// Do whatever you want with the $history array, I will just print it
var_dump($history);

?>
 
Status
This thread has been locked.
Top