0

我正在尝试使用图形 API 调用来返回登录到我的应用程序的用户的事件。但是,尽管我自己创建了一堆事件,但 $event 一直为空,有人可以帮忙吗?

这是我从登录到事件 api 调用的代码:

require_once('AppInfo.php');

// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
  header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  exit();
}

// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');    
require_once('sdk/src/facebook.php');

$facebook = new Facebook(array(
  'appId'  => AppInfo::appID(),
  'secret' => AppInfo::appSecret(),
  'sharedSession' => true,
  'trustForwarded' => true,
));

$user_id = $facebook->getUser();
if ($user_id) {
  try {
    // Fetch the viewer's basic information
    $basic = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    // If the call fails we check if we still have a user. The user will be
    // cleared if the error is because of an invalid accesstoken
    if (!$facebook->getUser()) {
      header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
      exit();
    }
  }

  // This fetches some things that you like . 'limit=*" only returns * values.
  // To see the format of the data you are retrieving, use the "Graph API
  // Explorer" which is at https://developers.facebook.com/tools/explorer/
  $likes = idx($facebook->api('/me/likes?limit=4'), 'data', array());

  // This fetches 4 of your friends.
  $friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());

  // And this returns 16 of your photos.
  $photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());

  // Fetch the event information
 // $events = idx($facebook->api('/me/events?limit=5'), 'data', array());
  $events = $facebook->api('/me/events','GET');
  print("11111");
  if($events == null) print("empty");
4

1 回答 1

2

我在您的示例中没有看到登录代码,您确定用户已登录吗?参见 PHP SDK“使用”:https ://github.com/facebook/facebook-php-sdk

无论如何,我只是在我的一个项目中尝试过这个,我通过相同的调用获得了用户事件,但我需要权限“user_events”:

$facebook->getLoginUrl(array('scope' => 'user_events'));
于 2013-05-02T21:44:11.800 回答