Mojang API - 检索用户名的最新 UUID [英] Mojang API - Retrieve latest UUID of username

查看:40
本文介绍了Mojang API - 检索用户名的最新 UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用 cURL 和 PHP 进行 API 调用,以检索使用过用户名的最新用户的 UUID.

使用 Mojang API:

<块引用>

用户名 -> 时间 UUID

例如进行 API 调用时:用户Chocolates"(根据 NameMC) 我获得了第一个使用该名称的用户的 UUID.

代码:

public function api_Changedto($uuid, $username){$ch = curl_init();//设置其他默认cUrl设置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);如果($响应){$decoded = json_decode($response);$match = false;foreach ($decoded as $userInfo){如果($匹配){$changedTo = ($userInfo->changedToAt + 3196800000)/1000;休息;}别的{if(strtolower($username) == strtolower($userInfo->name)){$match = 真;}}}}返回 $changedTo;}

<块引用>

?at=0 可用于获取该用户的原始用户的 UUID用户名

是否有解决方法来实现这一目标?

提前致谢,

解决方案

这应该是您要搜索的 API:https://api.mojang.com/users/profiles/minecraft/<用户名>

对该 URL 的 GET 请求应该告诉您当前使用指定用户名的帐户的 UUID,如果此时没有人使用该名称,则返回 HTTP 状态代码 204.

在这种情况下,要获取最新用户,您应该向该 URL 发出另一个请求,但这次您将添加 ?at=<currentUnixTimestampInSeconds - 30 days> 作为请求的查询字符串.

如果这再次为您提供 HTTP 204,请尝试使用 60 天前的时间戳,依此类推.重复此操作,直到您获得 UUID 或时间戳低于 1423008000,因为那是启用名称更改的时候.

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,

解决方案

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.

这篇关于Mojang API - 检索用户名的最新 UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆