-3

I want to display some information from the API https://steamgaug.es/api/v2 on my website.

This is my current code:

 $steamStatusJson = @file_get_contents("https://steamgaug.es/api/v2");
 $steamStatus = json_decode($steamStatusJson);
 $csgoStatus = $steamStatus->ISteamGameCoordinator->730->online;
 $csgoplayerssearching = $steamStatus->ISteamGameCoordinator->730->stats->players_searching;
 $csgoplayers =  $steamStatus->ISteamGameCoordinator->730->stats->players_online;

I always get this error message:

FATAL ERROR syntax error, unexpected '730' (T_LNUMBER), expecting identifier (T_STRING) or variable

piet.t
  • 11,718
  • 21
  • 43
  • 52
Enge
  • 113
  • 6

1 Answers1

1

as lone as you are decoding your json as an object, you can not use numbers as a properties names

so, you need to this line :

$csgoStatus = $steamStatus->ISteamGameCoordinator->730->online;

should be as follows :

$csgoStatus = $steamStatus->ISteamGameCoordinator->{"730"}->online;
//                                                 ^^^^^^^

also the same with those lines :

$csgoplayerssearching = $steamStatus->ISteamGameCoordinator->{"730"}->stats->players_searching;
$csgoplayers =  $steamStatus->ISteamGameCoordinator->{"730"}->stats->players_online;

or, simply by decoding your json as an array

$steamStatus = json_decode($steamStatusJson, true);

and then you can access it as :

$csgoStatus = $steamStatus['ISteamGameCoordinator']['730']['online'];
//....
hassan
  • 7,812
  • 2
  • 25
  • 36