PHP无法读取/接收响应

时间:2016-06-05 08:18:16

标签: php json steam

所以我要做的是从Steam API接收有关播放器的数据。 基本上,玩家通过Steam网站登录,然后被重定向到我的网站页面,其中有关玩家的数据被注册到数据库中。 似乎有关播放器的数据(从Steam API检索)是空的(无法检索)

当我尝试在浏览器中访问API时,它运行正常。

以下是注册数据的代码:

 $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=". $matches[1];
                $json_object = file_get_contents($url);
                $json_decoded = json_decode($json_object);
                foreach ($json_decoded->response->players as $player) {
                    $steamid = $player->steamid;
                    $name = $player->personaname;
                    $avatar = $player->avatar;
                }

                $hash = md5($steamid . time() . rand(1, 50));
                $sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
                $row = $sql->fetchAll(PDO::FETCH_ASSOC);
                if (count($row) == 0) {
                    $db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`, `avatar`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ", '" . $avatar . "')");
                } else {
                    $db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . ", `avatar` = '" . $avatar . "' WHERE `steamid` = '" . $steamid . "'");
                }

如果你想尝试自己的API,请复制$ url并用这个蒸汽ID替换$ matches [1]:76561198117114460

提前致谢, Guus Huizen

0 个答案:

没有答案