2013-07-26 26 views
0

我有以下的PHP代码来从蒸汽web api得到一个json文件。我似乎无法弄清楚为什么这没有收到任何信息。任何帮助,将不胜感激。使用PHP,请求蒸汽API调用解决虚荣名称,不起作用

请使用您自己的蒸汽API键。

<!DOCTYPE html> 
<html> 
<head> 
<title>Test</title> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
</head> 
<body> 
    <p>Welcome! <?php echo $_GET["fname"]; ?></p> 
    <p>Your steam id is 
<?php 
$username = $_GET["fname"]; 
$devKey = '<Insert Dev Key>'; 
$json_url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $devKey . '&vanityurl=' . $username; 
echo $json_url; 
$json_output = json_decode ($json_url, true); 
echo $json_output['response']['steamid']; 

?> 
</p> 
</body> 
</html> 

回答

2

你没有请求从URL中任何东西,你想json_decode URL本身。

而是尝试类似:

$json_url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=' . $devKey . '&vanityurl=' . $username; 
$res = file_get_contents($json_url); 
$json_output = json_decode ($res, true); 
var_dump($json_output); 

也可以看看到curl与蜜蜂打交道时,这是更加强大。

+0

呃....我的大脑真的在深层。非常感谢你,我一定会考虑卷曲。 – ThreeFold

+0

@ user1449940没问题。很高兴我能帮上忙。 – Jim