Error fetching API data

0

I can not get the data of a certain API can anyone help me? I've tried it in several ways. the error you are giving is:

  

Notice: Trying to get property of non-object in C: \ xampp \ htdocs \ test \ index.php on line 7

<?php
$api=file_get_contents("https://api.bf4stats.com/api/playerInfo?plat=pc&name=1ApRiL&output=js");
$defuse=json_decode($api);

echo $defuse->player->name;

?>
    
asked by anonymous 18.05.2017 / 23:46

1 answer

0

The output value passed as a parameter in the url should not be js, it should be json. The json_decode function, as you used it, will not interpret the result of your request as a valid json. Put in the url output = json.

<?php
$api=file_get_contents("https://api.bf4stats.com/api/playerInfo?plat=pc&name=1ApRiL&output=json");
$defuse=json_decode($api);

echo $defuse->player->name;

?>
    
19.05.2017 / 00:10