Mojang提供API - 获取用户名的最新UUID [英] Mojang API - Retrieve latest UUID of username

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

问题描述

我目前正在做使用卷曲用PHP来检索最新的已经使用的用户名用户的UUID的API调用。

使用 Mojang提供API


  

用户名 - > UUID在时间


使得例如API调用时:用户'的巧克力的'(根据 NameMC )我得到使用该名称的第一个用户的UUID。

code:

 公共职能api_Changedto($ UUID,$用户名)
   {
      $ 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_URLhttps://api.mojang.com/user/profiles/$ UUID/名称。);      curl_setopt($ CH,CURLOPT_CAINFO,证书/卷曲/ cacert.pem);      $响应= curl_exec($ CH);      如果($响应){
         $德codeD = json_de code($响应);         $匹配= FALSE;         的foreach($德codeD为$ USERINFO){            如果($比赛){               $ changedTo =($ userInfo-> changedToAt + 3196800000)/ 1000;
               打破;            }其他{
               如果(用strtolower($用户名)==用strtolower($ userInfo->名)){
                  $匹配= TRUE;
               }
            }
         }
      }
      返回$ changedTo;
   }


  

?在= 0可以用来获得的原始用户的UUID
  用户名


有一种解决方法,以实现这一目标?

由于提前,


解决方案

这应该是您正在搜索的API:
https://api.mojang.com/users/profiles/minecraft/<username>

A GET 请求,此URL应该告诉你的帐户的UUID目前使用指定的用户名,或HTTP状态code 204,如果名称不此时使用由任何人

要在这种情况下获得最新的用户,你应该让另一个请求到该网址,但这个时候,你会添加在=&LT; currentUnixTimestampInSeconds - 30天&GT; 作为查询字符串的请求。

如果这让你的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天全站免登陆