php - Facebook events graph not working -
i'm trying facebook page events. i've checked app id , app secret correct , still keep getting error.
<?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ob_start(); require 'facebook/src/facebook.php'; $fb = new facebook(array( 'appid'=>'appid', 'secret'=>'appsecret' ) ); $page_events = $fb->api('/pageid/events?fields=description,location,name,owner,cover,start_time,end_time', 'get'); printf ('<pre>%s</pre>', $page_events); ?>
the error message:
uncaught oauthexception: invalid oauth access token signature. thrown in
i'm not sure you've implemented or not code missing-
user login/authentication
the code not authenticating user. after creating
$fb
object; use this-$user_id = $fb->getuser(); if($user_id) { try { // proceed api calls - user authenticated @ point } catch(facebookapiexception $e) { $login_url = $fb->getloginurl(array( 'scope' => 'manage_pages')); header ("location: $login_url"); error_log($e->gettype()); error_log($e->getmessage()); } } else { $login_url = $fb->getloginurl(array( 'scope' => 'manage_pages')); header ("location: $login_url"); }
permissions
the documentation says-
for page events-
- any access token can used view publicly shared events.
- a
user access token
required retrieve events visible person. - a
page access token
required retrieve other events.
i think trying fetch events in page, you'll needing page access token.
to page access token:
$fb->api("/page_id?fields=access_token");
. use token return original call page's events-$page_events = $fb->api('/pageid/events?access_token='.$page_access_token.'&fields=description,location,name,owner,cover,start_time,end_time', 'get');
(if required, can never expiring page token page: see here)
Comments
Post a Comment