質問

I'm trying to get an Facebook page events. I've checked that the app id and app secret are correct and I still keep getting the 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 but your code is missing-

  1. User Login/Authentication

    The code is not authenticating the user. After creating the $fb object; use this-

    $user_id = $fb->getUser();
    if($user_id) {
       try {
    
          // proceed your api calls - user is authenticated at this 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");
    }
    
  2. Permissions

    The documentation says-

    For the page events-

    • Any access token can be used to view publicly shared events.
    • A user access token is required to retrieve events visible to that person.
    • A page access token is required to retrieve any other events.

    I think you are trying to fetch all the events in a page, so you'll be needing the page access token.

    To get a page access token: $fb->api("/PAGE_ID?fields=access_token");. Use the token return with your original call to get all the 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, you can also get a never expiring page token for a page: See here)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top