PHP with JSON decode and steam api -
i new php @ stage, same openid libraries. want make website steam users need display inventory. i've downloaded example things thing written still need else. training took else inventory, similiar. didn't make hope can me.
that's example looking @ while trying decode data.
{ "response": { "players": [ { "steamid": "76hidden", "communityvisibilitystate": 3, "profilestate": 1 } ] }
}
and code in php looks like
$url2 = file_get_contents("url"); $content = json_decode($url2, true); $_session['steam_steamid'] = $content['response']['players'][0]['steamid']; $steamprofile['steamid'] = $_session['steam_steamid'];
and 1 above working well. please explain me why there 0 between "steamid" , "players"? looks session name matters, right? doing tests , when changed name session didn't work.
so here's working on json code:
{ "friendslist": { "friends": [ { "steamid": "765hidden", "relationship": "friend", "friend_since": 1428495026 }, { "steamid": "764hidden", "relationship": "friend", "friend_since": 1355599210 }, { "steamid": "764hidden", "relationship": "friend", "friend_since": 1423504205 }, more friends ] } }
so want steamid , got no idea how it. i've tried relationship steamid used above:
$url3 = file_get_contents("url2"); $content2 = json_decode($url3, true); $_session['steam_relationship'] = $content2['friendslist']['friends'][0]['relationship']; $steamfriends['friend'] = $_session['steam_relationship'];
and of course echo $steamfriend['friend'] not working. see person made these php files know session names (if need right work). ideas can find it?
i feel ashamed can't figure myself.
regards.
the first json
{ "response": { "players": [ { "communityvisibilitystate": 3, "profilestate": 1, "steamid": "76hidden" } ] } }
translates php array
$content = array( "response" => array( "players" => array( array( "communityvisibilitystate" => 3, "profilestate" => 1, "steamid" => "76hidden" ) ) ) )
the players array of arrays (hash arrays), access first player need use index number ($content["response"]["players"][0]["steamid"]
) if there 1 player in players array.
to steamid
s second array, need run simple foreach:
$friendids = array(); foreach ($content2["friendslists"]["friends"] $friend) { $friendids[] = $friend["steamid"]; } # array("764hidden", "764hidden", "764hidden") var_export($friendids);
Comments
Post a Comment