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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀