PHP Script Undefined Property and Invalid Argument Errors -


i trying run php file , keep getting errors like

undefined property: stdclass::$games 

and

invalid argument supplied foreach() 

this picture of error http://imageshack.us/a/img845/6270/34356212.jpg , below script running minus steam api key.

<?php $api_key = '........';      //steam api key, required work $lines = file('parse1.txt');                        //reads in file list of user numbers $game_id = 550;                                     //steam game id, 440 tf2  foreach ($lines $usernumber) {                    //loops line line $link = 'http://api.steampowered.com/iplayerservice/getownedgames/v0001/?key=' . $api_key . '&steamid=' . $usernumber . '&format=json'; $json = file_get_contents($link);                   //reads link (this ^) $data = json_decode($json); foreach ($data->response->games $game) {      if ($game->appid == $game_id) {         $playtime = $game->playtime_forever;         if (($playtime < 5400) && ($playtime > 1)) {         //echo 'playtime ', $usernumber, ' ' . $playtime."<br>";                 echo $usernumber."<br>";                     }         }     } } ?> 

parse.txt contains steam id's eg (76561197987683795, 76561198063283029) assume has nested if commands, have no idea missing, huge! thanks

the response object in json not contain games array.

you'll want add more defense code handle situations external data not meet expectations:

if (!empty($data->response->games)) {     foreach ($data->response->games $game) {          if ($game->appid == $game_id) {             $playtime = $game->playtime_forever;             if (($playtime < 5400) && ($playtime > 1)) {             //echo 'playtime ', $usernumber, ' ' . $playtime."<br>";                     echo $usernumber."<br>";                         }             }         }     } } else {     echo 'games missing!'; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -