0

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>

google api source

5
  • You're missing the closing } for the foreach Commented Aug 11, 2014 at 16:46
  • so what does your echo & print_r statements show Commented Aug 11, 2014 at 16:48
  • @user574632 : it gives 'false' Commented Aug 11, 2014 at 16:52
  • @ExplosionPills: it was there, just not indented properly for code formatting. Commented Aug 11, 2014 at 17:08
  • if you get false, then file_get_contents FAILED and returned a boolean false. Commented Aug 11, 2014 at 17:08

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.