title: Get latest Facebook posts of page with PHP SDK
body: <p>The following code is inside a file called facebook_posts.php which I call from my index file like so: <code>&lt;?php require_once("http://www.example.com/design/php/facebook_posts.php"); ?&gt;</code>. However, where this code is put, there is no response. So neither success, nor the catch errors return an error (as I see it). I tried absolute URLs, but that didn't work either. (I hid the api and page information.) Apparently the content that follows the require_once (footer and scripts) aren't loaded. Something seems to go wrong when including the SDK.</p>
  
  <p>I'm not using composer, do I need to <code>require</code> the <code>Facebook\</code> files or <code>use</code> them? And which ones do I need for retrieving posts from a page?</p>
  
  <pre><code>&lt;?php
  // Defining FB SDK with absolute paths
  define('FACEBOOK_SDK_V4_SRC_DIR', 'http://example.com/design/Facebook/');
  require 'http://example.com/design/php/autoload.php';
  
  use Facebook\FacebookSession;
  use Facebook\FacebookRequest;
  use Facebook\GraphUser;
  use Facebook\FacebookRequestException;
  
  FacebookSession::setDefaultApplication('{my-app-id}','{my-app-secret}');
  
  $session = new FacebookSession('{my-long-lived-access-token}');
  
  // Get the GraphUser object for the current user:
  
  try {
  $request = new FacebookRequest(
    $session,
    'GET',
    '/{my-page-id}/feed'
  );
  $response = $request-&gt;execute();
  $graphObject = $response-&gt;getGraphObject();
  
  var_dump($graphObject);
  echo graphObject;
  echo "banana";
  
  } catch (FacebookRequestException $e) {
    echo "API ERROR";
  } catch (\Exception $e) {
    echo "other error";
  }
  
  ?&gt;
  </code></pre>
  
  <p>EDIT: so I just <a href="https://stackoverflow.com/questions/23569934/error-class-facebook-facebooksession-not-found-with-the-facebook-php-sdk#27522863">required in</a> all the FB files, and that seems to work. However, I don't know how to traverse/iterate the object that is returned. I.e. how to loop through the different posts (the four latest posts by the page) and echo them in HTML. A base structure would look like this:</p>
  
  <pre><code>&lt;time&gt;{publish date}&lt;/time&gt;
  &lt;p&gt;{post message}&lt;/p&gt;
  &lt;a href="{link to included url}"&gt;{title to included url}&lt;/a&gt;
  </code></pre>