2014-09-02 106 views
0

我想要在PHP中申請我的Facebook網站應用程序的基本權限。我有以下代碼:Facebook的PHP SDK範圍要求

FacebookSession::setDefaultApplication('xxxxxxx', 'xxxxxxxx'); 

$helper = new FacebookRedirectLoginHelper('http://localhost:54321/xxxx.php'); 

try { 
    $session = $helper->getSessionFromRedirect(); 
} catch(FacebookRequestException $ex) { 
} catch(Exception $ex) { 
} 

if (isset($session)) { 
    $request = new FacebookRequest($session, 'GET', '/me'); 
    $response = $request->execute(); 
    $graphObject = $response->getGraphObject(); 

$params = array(
    'scope' => 'basic_info' 
); 

    echo print_r($graphObject, 1); 
} else { 
    echo '<a href="' . $helper->getLoginUrl($params) . '">Login</a>'; 
} 

這提供了一個URL鏈接,但是當我點擊它,它重定向到一個網站的網址和失敗,一個500。如果我從getLoginURL刪除$params,它的功能正常。我如何使用它來請求更多的權限?

+0

'basic_info'權限在API v2中不再存在,它已被替換爲'public_profile'。 – CBroe 2014-09-02 09:54:30

+0

而當你調用getLoginURL $ params從未設置。 – WizKid 2014-09-02 10:02:15

回答

0
  1. getLoginUrl()方法接受一個數字數組的權限。您正在使用關聯數組。正確的用法是這樣的:$params = array('email','public_profile');

  2. 由於@WizKid指出的那樣,$params陣列被你if (isset($session))語句的第一塊組所以它永遠不會被傳遞到getLoginUrl()

  3. 正如@CBroe指出的,basic_info在圖2.x中被刪除,現在被拆分爲public_profileuser_friends