Facebook SDK 4 for PHP -没有登录抓取一些事件


Facebook SDK 4 for PHP - no login grab some events

我尝试使用Facebook SDK 4 for PHP,

,但有一件事我不明白:使用它与应用程序访问令牌!

我尝试不同的令牌初始化FaceBookSession,但我不明白它是如何工作的…:/

,例如:

$request = new FacebookRequest(
  $session,
  '/480602392011337/events?fields=id,end_time,description,is_date_only,location,name,start_time&since='.date('Y-m-d',strtotime('-1 year')).'&until='.date('Y-m-d',strtotime('+1 year')).'&limit=500',
  //'/480602392011337/events',
  'GET'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();

谢谢你的帮助!:)

我终于找到了解决方案(感谢Google),只需使用FacebookSession::newAppSession();

// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('xxxxxx','xxxxxxx');
//  Get the access token for this app
$session = FacebookSession::newAppSession();
// make the API call, $datas contains the events for the facebook fan page BDE Polytech Marseille
try {
$request = new FacebookRequest(
    $session,
    'GET',
    '/{page-id}/events?fields=id,end_time,description,is_date_only,location,name,start_time&since='.strtotime('-1 year').'&until='.strtotime('+1 year').'&limit=500'
);
$response = $request->execute();
$datas = $response->getGraphObject()->asArray();
}catch (FacebookRequestException $e) {
    echo $e->getMessage();
}catch ('Exception $e) {
    echo $e->getMessage();
}