0

SteamのログインでWebサイトを作成しようとしていますが、JSONから値を呼び出そうとすると、機能しません。JSON値を取得することを除いて、すべてがソースコードで機能します。Steam IDを印刷してみたので、IDが機能することはわかっています。URLも機能します。

これが私のソースコードです

<?php
require 'openid.php';
try {
    $openid = new LightOpenID('workinganonymouswebsite.com');
    if (!$openid->mode) {
        $openid->identity = 'http://steamcommunity.com/openid';
        header('Location: ' . $openid->authUrl());
    } elseif ($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        $steamurl = ($openid->validate() ? $openid->identity . '' : 'error');
        if ($steamurl == 'error') {
            print "There was an error signing in.";
        } else {
            $id          = end(explode('/', $steamurl));
            $jsonurl     = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXX&steamids=" . $id . "&format=json";
            $json        = file_get_contents($jsonurl, 0, null, null);
            $json_output = json_decode($json);
            echo $json_output['players']['personaname'];
        }
    }
} catch (ErrorException $e) {
    echo $e->getMessage();
}
?>

これがWebサイトのJSONです。

{
"response": {
    "players": [
        {
            "steamid": "76561198049205920",
            "communityvisibilitystate": 3,
            "profilestate": 1,
            "personaname": "baseman101",
            "lastlogoff": 1357603378,
            "profileurl": "http://steamcommunity.com/id/baseman101/",
            "avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/24/24bb7c0505db7efe1f1a602d09a5ea412e0ab4bd.jpg",
            "avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/24/24bb7c0505db7efe1f1a602d09a5ea412e0ab4bd_medium.jpg",
            "avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/24/24bb7c0505db7efe1f1a602d09a5ea412e0ab4bd_full.jpg",
            "personastate": 1,
            "primaryclanid": "103582791429521408",
            "timecreated": 1316469294,
            "loccountrycode": "US",
            "locstatecode": "VA",
            "loccityid": 3918
        }
    ]

}
}

私はすべてをグーグルで検索してみました。見逃してしまったことがありましたらごめんなさい。

4

1 に答える 1

1

ご協力いただきありがとうございます。基本的に、JSON コードを変数に入れ、Steam Web サイトから取得します。これが最善の解決策であり、私はそれに固執しています。

<?php
require 'openid.php';
try {
$openid = new LightOpenID('blah.com');
if (!$openid->mode) {
    $openid->identity = 'http://steamcommunity.com/openid';
    header('Location: ' . $openid->authUrl());
} elseif ($openid->mode == 'cancel') {
    echo 'User has canceled authentication!';
} else {
    $steamurl = ($openid->validate() ? $openid->identity . '' : 'error');
    if ($steamurl == 'error') {
        print "There was an error signing in.";
    } else {
        $id          = end(explode('/', $steamurl));
        $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
        $json_source = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXX&steamids=" . $id . "&format=json",false,$context);
        $json_output = json_decode($json_source,true);
        $json_output->response->players[0]->personaname;
        echo $json_output["response"]["players"][0]["personaname"];
    }
}
} catch (ErrorException $e) {
echo $e->getMessage();
}
?>

助けてくれてありがとう、Passerbyとhakre。

将来的には、クッキーを作成する必要があり、すべての簡単なものを作成する必要があります。私は実際にそれを今始めています。

于 2013-01-09T01:27:22.370 に答える