Jer*_*era 3 php email facebook codeigniter facebook-graph-api
我似乎无法提供所需的电子邮件权限.
如果用户取消登录FB登录的电子邮件,我的代码就会崩溃.当我尝试围绕这个问题编写代码时(尝试提醒用户接受必要的电子邮件权限.),它将无法正常工作; 用户必须在FB设置中手动撤销App的访问权限,这显然是不可能的.
那么我如何才能将电子邮件权限作为我的应用程序/网站的一部分?
Tbh,我无法通读整个Facebook API文档而不会轻描淡写.
这是我目前的情况:
var $user = null;
function __construct()
{
//blahblahlblah
//blahblahblah (Code needed for facebook login to work)
$this->user = $this->facebook->getUser();
if ($this->user)
{
try
{
// Proceed knowing you have a logged in user
$this->user = $this->facebook->api('/me');
$this->logoutUrl = $this->facebook->getLogoutUrl( array('next' => base_url() . 'connect/logout') );
}
catch (FacebookApiException $e)
{
error_log($e);
$this->user = null;
}
}
}
function process()
{
// If the Facebook user allows his/her email to be shared.
// [If they don't, skip to the `else` statement below]
if (isset($this->user['email']))
{
//Great! I can process normally
}
// If the Facebook user doesn't share their email.
else
{
//What do I do here?
//I'm not sure how the OAuth works, so that's why im checking
echo 'email is required. line 86 , connect.php controller';
}
}
Run Code Online (Sandbox Code Playgroud)
在继续应用程序逻辑之前,应检查收到的访问令牌.这里描述了如何做到这一点:
https://developers.facebook.com/docs/facebook-login/permissions/v2.0#checking
如果您确认用户未授予email权限,您可以将其重新发送到权限对话框,如下所述:
https://developers.facebook.com/docs/facebook-login/permissions/v2.0#handling
引用:
如果有人拒绝了您的应用的权限,则登录对话框不会让您的应用重新请求权限,除非您传递
auth_type=rerequest了您的请求.