1

I have:

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']), true);


var_dump($user);

which works fine and gives profile output.

But:

$events = json_decode(file_get_contents(
    'https://graph.facebook.com/me/events?access_token=' .
    $cookie['access_token']), true);


var_dump($events);

gives:

object(stdClass)#5 (1) { ["data"]=> array(0) { } }

I'm not sure if this is an empty object, or if I'm not accessing what's inside 'data' correctly. But, I know there are in fact events associated with my profile. Permissions have been granted, so that's not the problem. Anyone know how to return all event names for my profile?

Shawn
  • 11
  • 1

1 Answers1

0

In order to get events in PHP you have to follow these steps,

Request a proper Access Token follow this link facebook: permanent Page Access Token?

Replace your Access token below texted YOUR_ACCESS_TOKEN field

    <?php
        $json_string = 'https://graph.facebook.com/5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=999';
        $obj = json_decode(curl_get_contents($json_string),true);

        foreach ($obj['data'] as $key => $value) {
          echo @$value['id'];
          echo @$value['name'];
          echo @$value['start_time'];
          echo @$value['place'];
          echo @$value['cover']['source'];
        }

        function curl_get_contents($url)
        {
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         $data = curl_exec($ch);
         curl_close($ch);
         return $data;
       }
     ?>
Community
  • 1
  • 1
Googlian
  • 6,077
  • 3
  • 38
  • 44