2013-05-02 100 views
0

我正在嘗試使用圖形API調用來返回登錄到我的應用程序的用戶的事件。然而,$ event始終爲空,雖然我自己創建了一堆事件,任何人都可以幫忙嗎?facebook圖形API不返回事件

這裏是我的代碼登錄到事件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"); 

回答

2

我認爲沒有登錄代碼在你的榜樣,你一定要在用戶登錄?見PHP SDK「用法」:https://github.com/facebook/facebook-php-sdk

無論如何,我只是想這在我的項目之一,我得到同樣的呼叫的用戶事件,但我需要的權限「user_events」:

$facebook->getLoginUrl(array('scope' => 'user_events')); 
+0

感謝幫助!我實際上使用了不同的方式登錄使用JavaScript和登錄按鈕的幫助。我們在我們的範圍內添加了「user_events」作爲

,然後它的工作! – 2013-05-02 22:12:25

+0

啊,javascript總是更好的登錄(可用性和東西),這是完美的。很高興我能幫上忙 :) – luschn 2013-05-02 22:54:04

相關問題