将Steam API信息提取到页面

我从Valve那里找到了一个很棒的Steam API,我现在想知道如何通过 一。 示例: $ steam ['response'] ['players'] ['personastate'] </ code>。 它不需要是那个解决方案。 我只是键入了一些内容:)</ p>

请求将如下所示:</ p>

  {
“response”:{
“玩家”:[
{
“steamid”:“{hidden}”,
“communityvisibilitystate”:3,
“profilestate”:1,
“personaname”:“nhagyavi”,
“lastlogoff “:1317692549,
”“commentpermission”:1,
“profileurl”:“http:\ / \ / steamcommunity.com \ / id \ / nhagyavi \ /”,
“avatar”:“http:\ / \ /media.steampowered.com\/steamcommunity\/public\/images\/avatars\/c2\/c25479aeea82f85eb1134bfcc8e064dcef1d361f.jpg",,n“avatarmedium”:“http:\ / \ / media.steampowered.com \ / steamcommunity \ /public\/images\/avatars\/c2\/c25479aeea82f85eb1134bfcc8e064dcef1d361f_medium.jpg",nn“avatarfull”:“http:\ / \ / media.steampowered.com \ / steamcommunity \ / public \ / images \ / avatars \ / c2 \ /c25479aeea82f85eb1134bfcc8e064dcef1d361f_full.jpg“,
”personastate“:1,\ n“realname”:“Erik Edgren”,
“primaryclanid”:“103582791429525632”,
“timecreated”:1106321372,
“gameserverip”:“217.163.23.35:7777”,“n”gameextrainfo“:”Red 管弦乐队2:斯大林格勒英雄“,
”游戏玩法“:”35450“,
”gameserversteamid“:”90083758048089092“,
”loccountrycode“:”SE“,
”locstatecode“:”{hidden}“,

“loccityid”:{hidden}
}
]

}
}
</ </ code> </ pre>

如何解决此问题? 提前致谢!</ p>
</ div>

展开原文

原文

I have found a great Steam API from Valve them self and I wonder now how I can put the specific information one by one. Example: $steam['response']['players']['personastate']. It doesn't need to be that solution. I just typed something :)

The request will be like this one below:

{
    "response": {
        "players": [
            {
                "steamid": "{hidden}",
                "communityvisibilitystate": 3,
                "profilestate": 1,
                "personaname": "nhagyavi",
                "lastlogoff": 1317692549,
                "commentpermission": 1,
                "profileurl": "http:\/\/steamcommunity.com\/id\/nhagyavi\/",
                "avatar": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/c2\/c25479aeea82f85eb1134bfcc8e064dcef1d361f.jpg",
                "avatarmedium": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/c2\/c25479aeea82f85eb1134bfcc8e064dcef1d361f_medium.jpg",
                "avatarfull": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/c2\/c25479aeea82f85eb1134bfcc8e064dcef1d361f_full.jpg",
                "personastate": 1,
                "realname": "Erik Edgren",
                "primaryclanid": "103582791429525632",
                "timecreated": 1106321372,
                "gameserverip": "217.163.23.35:7777",
                "gameextrainfo": "Red Orchestra 2: Heroes of Stalingrad",
                "gameid": "35450",
                "gameserversteamid": "90083758048089092",
                "loccountrycode": "SE",
                "locstatecode": "{hidden}",
                "loccityid": {hidden}
            }
        ]

    }
}

How do I fix this? Thanks in advance!

1个回答

Looks like JSON. You need json.decode

$json_object=
file_get_contents("http://api.steampowered.com/");

        $json_decoded = json_decode($json_object);
        //var_dump($json_decoded);
        echo $json_decoded->response->players[0]->lastlogoff;

Outputs

1317711877
duankang5285
duankang5285 我来自瑞典:P Steam ID是从Steam API页面链接的。
接近 9 年之前 回复
dounangqie4819
dounangqie4819 您现在可以删除您的蒸汽ID! :P
接近 9 年之前 回复
dt56449492
dt56449492 我已经更新了我的代码。
接近 9 年之前 回复
duanhui1185
duanhui1185 我只使用print_r()处理以下代码。 如何从此代码中打印出特定数据? $ json1 = file_get_contents(“api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002 / ...”); $ tree1 = json_decode($ json1); $ tree1-> response-> players [0] - > steamid; echo'<pre> '; print_r($ tree1); echo'</ pre>';
接近 9 年之前 回复
dpafea04148
dpafea04148 JSON只是编码,如果启用了allow_url_fopen,则可以使用file_get_contents()来获取远程数据(在大多数情况下为true),否则您可以使用CURL或者使用某些库来为您抽象。 我经常使用Zend_Http_Client。
接近 9 年之前 回复
dshu1235
dshu1235 当然。 api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/...
接近 9 年之前 回复
drny20290570
drny20290570 你能提供样品链接吗? 那个说未经授权。
接近 9 年之前 回复
dongxixiu9134
dongxixiu9134 谢谢,但你的例子没有打印任何东西。 如何从其他页面获取内容,如api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002 / ...与JSON?
接近 9 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐