Facebook SDK 4 for PHP-无需登录获取某些事件
我尝试使用Facebook SDK 4 for PHP 但有一件事我不明白:将它与应用程序访问令牌一起使用 我尝试了不同的令牌来初始化FaceBookSession,但我不明白它是如何工作的…:/ 例如,使用此示例代码:Facebook SDK 4 for PHP-无需登录获取某些事件,php,facebook,facebook-graph-api,facebook-php-sdk,facebook-sdk-4.0,Php,Facebook,Facebook Graph Api,Facebook Php Sdk,Facebook Sdk 4.0,我尝试使用Facebook SDK 4 for PHP 但有一件事我不明白:将它与应用程序访问令牌一起使用 我尝试了不同的令牌来初始化FaceBookSession,但我不明白它是如何工作的…:/ 例如,使用此示例代码: $request = new FacebookRequest( $session, '/480602392011337/events?fields=id,end_time,description,is_date_only,location,name,start_time
$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();
谢谢你的帮助!:) 我终于找到了解决方案(thx-Google),只需使用
FacebookSession::newAppSession()代码>
我不知道如何拥有有效的访问令牌。。。使用此命令:$session=newfacebooksession('xxxxxxxxx')代码>感谢您提示调用过去的事件。我从未收到过任何事件,直到我意识到只有过去的事件(
// 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();
}