2011-07-21 42 views
3

我需要檢索用戶的電子郵件,當他們在我的網站上使用Facebook登錄。 Facebook的登錄URL中有一個scope參數,用於請求這些擴展權限。我究竟將這些代碼添加到哪些代碼中,以便將範圍正確設置爲包含電子郵件?如何正確使用Facebook範圍獲取用戶電子郵件?

/** 
* Get a Login URL for use with redirects. By default, full page redirect is 
* assumed. If you are using the generated URL with a window.open() call in 
* JavaScript, you can pass in display=popup as part of the $params. 
* 
* The parameters: 
* - redirect_uri: the url to go to after a successful login 
* - scope: comma separated list of requested extended perms 
* 
* @param Array $params provide custom parameters 
* @return String the URL for the login flow 
*/ 
public function getLoginUrl($params=array()) { 
$this->establishCSRFTokenState(); 
$currentUrl = $this->getCurrentUrl(); 
return $this->getUrl(
    'www', 
    'dialog/oauth', 
    array_merge(array(
       'client_id' => $this->getAppId(), 
       'redirect_uri' => $currentUrl, // possibly overwritten 
       'state' => $this->state), 
       $params)); 
} 

回答

3

添加範圍參數:

public function getLoginUrl($params=array()) { 
$this->establishCSRFTokenState(); 
$currentUrl = $this->getCurrentUrl(); 
return $this->getUrl(
    'www', 
    'dialog/oauth', 
    array_merge(array(
       'client_id' => $this->getAppId(), 
       'redirect_uri' => $currentUrl, // possibly overwritten 
       'state' => $this->state, 
       'scope'=>'email'), 
       $params)); 
} 
+0

尼斯,我只要我能接受這一點。你知道Facebook是否允許使用Facebook登錄的應用/網站存儲這些信息,或者是否違反了他們的政策?我可以存儲什麼? – tnw

+2

facebook的數據存儲政策http://developers.facebook.com/policy/#data – Gazler

+0

據我所知,您可以存儲用戶數據,但Facebook建議您不要求權限(因此更多的數據),這是不相對於您的網站或你根本不會使用。 –

相關問題