Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP (facebook feed)issue

Options
  • 26-04-2012 11:53pm
    #1
    Registered Users Posts: 986 ✭✭✭


    hi all, ive been trying to get a facebook feed to display on a website.

    the php is sound, or so i think....

    but its throwing up two red flags
    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>
    <?php
    //Get the contents of the Facebook page
    $FBpage = file_get_contents('https://graph.facebook.com/PAGE_ID/feed?access_token=ACCESS_TOKEN');
    //Interpret data with JSON
    $FBdata = json_decode($FBpage);
    //Loop through data for each news item
    foreach ($FBdata->data as $news )
    {
    //Explode News and Page ID's into 2 values
    $StatusID = explode("_", $news->id);
    echo '<li>'
    //Check for empty status (for example on shared link only)
    if (!empty($news->message)) { echo $news->message;}
    echo '</li>'
    }
    ?>
     </body>
    </html>
    

    the lines that are off are:

    if (!empty($news->message)) { echo $news->message;}

    and the last }

    any help greatly appreciated.


Comments

  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    You're missing some semicolons there.

    Add them on to the two lines:

    [PHP]
    echo '<li>';
    echo '</li>';
    [/PHP]

    Probably have to set something for ACCESS_TOKEN too, not sure where you'll find it though, haven't used facebook much.


  • Registered Users Posts: 986 ✭✭✭wild_eyed


    thank you, i already have the access token from facebook.

    when the corrected code is inserted into my php page.

    it returnd the following output, which is just part of the code. the php is within a div
    <div style="position: absolute; top: 247px; left: 269px; width: 509px; height: 674px; z-index: 64; background-color: #333333; layer-background-color: #333333; border: 1px none #000000;" id="element440">
            
      <?php
    //Get the contents of the Facebook page
    $FBpage = file_get_contents('https://graph.facebook.com/xxxxxxxxx/feed?access_token=xxxxxxxx');
    //Interpret data with JSON
    $FBdata = json_decode($FBpage);
    //Loop through data for each news item
    foreach ($FBdata->data as $news )
    {
    //Explode News and Page ID's into 2 values
    $StatusID = explode("_", $news->id);
    echo '<li>';
    //Check for empty status (for example on shared link only)
    if (!empty($news->message)) { echo $news->message;}
    echo '</li>';
    }
    ?>
            
            </div>
    

    and the output:
    data as $news ) { //Explode News and Page ID's into 2 values $StatusID = explode("_", $news->id); echo '
    '; //Check for empty status (for example on shared link only) if (!empty($news->message)) { echo $news->message;} echo '
    '; } ?>
    

    im not a complete noob, but php has me puzzled...


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    That shouldn't be happening at all with the code you posted.
    There's something wrong further up the line.
    The output is starting after:
    foreach ($FBdata->
    The closing angle bracket looks like it's closing off an open tag somewhere.
    I was able to recreate this problem output by attempting using PHP "short tags" (which I have turned off) <? ?> rather than the normal form of <?php ?>
    Go through your code and make sure every bit of php you're using is opened with <?php


  • Registered Users Posts: 241 ✭✭fcrossen


    Check the bleedin' obvious... as well as the <?php ?> tags mentioned above, make sure your webserver is parsing the file. Usually this means the filename must end in '.php'.

    Also I guess you are relying on your code editor to tell you where the PHP errors are. It is much better to keep an eye on your error log - you'll get more information that way.


Advertisement