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 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现