2015-12-27 52 views
-4

我試圖使用mojang api來檢索他們的用戶名這樣的用戶Minecraft UUID是我:的Json解碼從URL中不工作

//Get Player UUID from name 
$uuid = "Error obtaining uuid"; 
$json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' + $_GET['name']); 
$obj = json_decode($json); 
$uuid = $obj->id; 

變量$uuid包含null和林不知道做什麼IM錯誤我確保我設置$_GET參數去player.php/?name=_Joosh但仍然沒有?

+0

'$ json'上有什麼嗎?請''var_dump($ json)',[edit](http://stackoverflow.com/posts/34486105/edit)您的問題併發布更新... – FirstOne

+0

@FirstOne返回:bool(false) – Joosh

+2

請檢查如果[allow_url_fopen](http://stackoverflow.com/questions/13433660/how-to-check-if-allow-url-fopen-is-enabled-or-not)已啓用。此外,PHP使用'.'來[concat string](http://php.net/manual/en/language.operators.string.php)。 – FirstOne

回答

1

您必須使用dot操作符進行連接而不加。嘗試下面的代碼片段。

//Get Player UUID from name 
$name = 'john'; 
$uuid = "Error obtaining uuid"; 
// Tested with simple variable 
// $json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $name); 
$json = file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $_GET['name']); 
$obj = json_decode($json); 
$uuid = $obj->id; 

print $uuid;