dongxiao0449 2013-07-26 08:08
浏览 84
已采纳

使用PHP调用Steam API,请求解析虚名,不起作用

I have the following php code to get a json file from the steam web api. I can't seem to figure out why this isn't recieving any information. Any help would be appreciated.

Please use your own steam api key.

<!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>
  • 写回答

1条回答

  • dphj737575 2013-07-26 08:12
    关注

    You aren't requesting anything from the url, you're trying to json_decode the url itself.

    Instead try something like:

    $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);
    

    Also have a look into curl as this is more powerful when dealing with apis.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作