doufeixuan8882 2014-04-23 20:53
浏览 35
已采纳

Facebook事件图不起作用

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

  • 写回答

1条回答 默认 最新

  • dongtingrun4973 2014-04-24 06:01
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?