Reputation: 115
I want to display the actvivites posts results which i recieved through goole json api url on my website, therefore i used following codeings. but its not displaying results. please advice .
<?php
$jsonurl = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=%23fifa&alt=json&key={API KEY }";
$json = file_get_contents($jsonurl);
$json_output = json_encode($json);
//echo json_encode($json);
echo '<pre>';
//echo json_encode($json);
print_r($json_output);
echo '</pre>';
?>
<div class="datagrid ">
<?php
$json=array();
foreach ($json_output["data"] as $json_result) {
$json[] = array(
'value' => $json_result["title"],
'value' => $json_result["url"]
);
?>
<div ><table>
<tbody>
<TR>
<TD><h3><?php echo $json_result["title"];?></h3></TD>
<TD><h3><?php echo $json_result["url"];?></h3></TD>
</TR>
</tbody>
</table>
</div>
<?php
}
?>
</div>
Upvotes: 0
Views: 620
Reputation: 552
I can point out a few things in your code. Some definitely need a little help.
You have these two lines.
$json = file_get_contents($jsonurl);
$json is already a json encoded string, I presume instead of the following line. You actually want to decode it into an array.
$json_output = json_encode($json);
Such as
$json_output = json_decode($json, true);
notice I used the true parameter to make sure it gets all the way decoded instead of an array of std class variables. but I suppose it would depend on what you want in your code.
Upvotes: 1