Возникла неизвестная проблема, которую я не могу найти.
Делаю авторизацию с помощью Steam Web API (подробнее).
Есть ссылка:
http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$STEAMAPI&steamids=$matches[1]
где $STEAMAPI
— переменная с ключом;
$matches[1]
— переменная, значение которой будет после авторизации в Steam, steamid
.
По этим данным в формате JSON будет выводится информация об аккаунте Steam. Почему-то с помощью функций file_get_contents
, json_decode
не удается вывести информацию об аккаунте. Например, есть информация —
http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=98798566D0A8DA0C305F49760266BBF4&steamids=76561198039950522
Как видим, тут данные приведены на примере. Сам код для вывода этой информации:
$url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$STEAMAPI&steamids=$matches[1]");
$data = (array) json_decode($url)->response->player[0];
print_r($data);
Все переменные, которые входят в ссылку, не пустые, и я их проверял — всё отлично.
Но почему-то массив пустой оказывается.
Код полностью:
<?php
require 'openid/openid.php';
$STEAMAPI = "98798566D0A8DA0C305F49760266BBF4";
try
{
$openid = new LightOpenID('http://steam-tests2.hol.es/register.php');
if(!$openid->mode)
{
if(isset($_GET['login']))
{
$openid->identity = 'http://steamcommunity.com/openid/?l=english';
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<input type="image" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png">
</form>
<?php
}
elseif($openid->mode == 'cancel')
{
echo 'User has canceled authentication!';
}
else
{
if($openid->validate())
{
$id = $openid->identity;
// identity is something like: http://steamcommunity.com/openid/id/76561197960435530
// we only care about the unique account ID at the end of the URL.
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
echo "User is logged in (steamID: $matches[1])\n";
$url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$STEAMAPI&steamids=$matches[1]");
$data = (array) json_decode($url)->response->player[0];
print_r($data);
}
else
{
echo "User is not logged in.\n";
}
}
}
catch(ErrorException $e)
{
echo $e->getMessage();
}
?>