我目前正在嘗試使用cURL和PHP進行API調用,以檢索使用用戶名的最新用戶的UUID。Mojang API - 檢索最新的用戶名UUID
使用Mojang API:
用戶名 - > UUID在時間
使得例如API調用時:用戶 '巧克力'(已經用於通過根據四個用戶到NameMC)我得到使用該名稱的第一個用戶的UUID。
代碼:
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;
}
在= 0可以被用來獲取 用戶名
有一種變通方法來實現這一目標的原始用戶的UUID?
由於提前,
似乎curl正在使用緩存。 你應該看看這篇文章:http://stackoverflow.com/questions/15493769/is-there-a-way-to-tell-curl-to-not-use-cache –
你是什麼意思,它doesn'真的有道理。如何解決我得到第一個給定UUID的問題? –
澄清一下,當你說'最新'時,你的意思是'最近',對吧?但是,如果現在沒有人使用該名稱,請查找使用該名稱的_last_人? – Pokechu22