title: Getting events from Facebook
body: <p>I am currently trying to get and parse events of a user by making use of the Facebook api. In order to do this, I am making use of the function below.</p>
  
  <pre><code>function facebook_get_events($facebookSession) {
  
          // make the API call and get array of event objects
          $events = (new FacebookRequest($facebookSession, 'GET', '/me/events')-&gt;execute()-&gt;getGraphObject();
  
          log("Got events from facebook " . count($events));
  
          foreach ($events as $event) {
             echo $event-&gt;getProperty('id');
          }
  
          return events;
  }
  </code></pre>
  
  <p><strong>Problem:</strong> The problem is that its not working. In the log I am noticing that only one element is in the array. By the way, I am assuming that events is an array because, according to Facebook's documentation, the response is "an array of Event objects". <a href="https://developers.facebook.com/docs/graph-api/reference/v2.1/user/events" rel="nofollow">Click here to check out the doc link</a>.</p>
  
  <p>With regards to the printing of the id, nothing is being shown.</p>
  
  <p>In order to check whether the request is correct, I also used Facebook's Graph API Explorer, and it is returning the list of events correctly. The result structure is shown below (Information has been removed due to privacy concerns).</p>
  
  <pre><code>    {
        "data": [
          {
            "name": "...", 
            "start_time": "...", 
            "location": "...", 
            "rsvp_status": "...", 
            "id": "..."
          }, 
          {
            "name": "...", 
            "start_time": "...", 
            "timezone": "...", 
            "rsvp_status": "...", 
            "id": "..."
          }
        ], 
  .....
  }
  </code></pre>
  
  <p>I have also checked whether my permissions are correct, and I can confirm that I am including the user_events permission. I think my issue is more related on how I am parsing the response. </p>
  
  <p>As requested by a comment, I have also done a var_dump on events. The following is a snapshot of what I received.</p>
  
  <blockquote>
  <pre><code>object(Facebook\GraphObject)#5 (1) {
  ["backingData":protected]=&gt;
  array(2) {
  ["data"]=&gt;
  array(25) {
  [0]=&gt; object(stdClass)#6 (5) {
  ["id"]=&gt; string(15) “…”
  ["name"]=&gt; string(11) “..”.
  [“location"]=&gt; string(14) “…”
  ["start_time"]=&gt; string(24) “…”
  </code></pre>
  </blockquote>
  
  <p><strong>Progress 1:</strong> </p>
  
  <p>I also tried making use of this code, calling the 'data' property, but still did not manage.</p>
  
  <pre><code>function facebook_get_events($facebookSession) {
  
          // make the API call and get array of event objects
          $events = (new FacebookRequest($facebookSession, 'GET', '/me/events')-&gt;execute()-&gt;getGraphObject();
  
          log("Got events from facebook " . count($events-&gt;getProperty('data')));
  
          foreach ($events-&gt;getProperty('data') as $event) {
             echo $event-&gt;getProperty('id');
          }
  
          return events;
  }
  </code></pre>
  
  <p>The above code prints out nothing.</p>