Error picking up API data

Asked

Viewed 55 times

0

I’m not getting the data from a certain API, can anyone help me? I’ve tried a number of ways. the mistake you’re making is :

Notice: Trying to get Property of non-object in C: xampp htdocs teste 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;

?>

1 answer

0

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

<?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;

?>
  • Perfect, lack of attention already thank you now it worked!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.