问题
I am currently trying to make an API call using cURL with PHP to retrieve the UUID of the latest user that has used a username.
Using the Mojang API:
Username -> UUID at time
When making an API call for example: the user 'Chocolates' (Which has been used by four users according to NameMC) I get the UUID of the first ever user using that name.
Code:
public function api_Changedto($uuid, $username)
{
$ch = curl_init();
//Set other default cUrl settings
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_POST, 0);
curl_setopt( $ch, CURLOPT_URL, "https://api.mojang.com/user/profiles/" . $uuid . "/names");
curl_setopt( $ch, CURLOPT_CAINFO, "certificates/curl/cacert.pem");
$response = curl_exec($ch);
if($response) {
$decoded = json_decode($response);
$match = false;
foreach ($decoded as $userInfo){
if($match){
$changedTo = ($userInfo->changedToAt + 3196800000) / 1000;
break;
}else{
if(strtolower($username) == strtolower($userInfo->name)){
$match = true;
}
}
}
}
return $changedTo;
}
?at=0 can be used to get the UUID of the original user of that username
Is there a workaround to achieve this?
Thanks in advance,
回答1:
This should be the API you are searching for:
https://api.mojang.com/users/profiles/minecraft/<username>
A GET
request to this URL should tell you the UUID of the account currently using the specified username, or HTTP status code 204 if the name isn't used by anybody at this time.
To get the latest user in this case, you should make another request to that URL, but this time you would add ?at=<currentUnixTimestampInSeconds - 30 days>
as query string to the request.
If this gives you HTTP 204 again, try a timestamp 60 days ago, and so on. Repeat this until you got the UUID or the timestamp is lower than 1423008000, because thats when name changing was enabled.
来源:https://stackoverflow.com/questions/34923876/mojang-api-retrieve-latest-uuid-of-username