gpt4 book ai didi

php - 如何在使用 FB 登录名登录/注册用户时需要电子邮件权限?

转载 作者:可可西里 更新时间:2023-11-01 00:44:30 25 4
gpt4 key购买 nike

我似乎无法获得所需的电子邮件权限。

如果用户在 FB 登录时取消勾选电子邮件,我的代码就会崩溃。当我尝试围绕这个问题编写代码时(尝试提醒用户接受必要的电子邮件权限。),它不会工作;用户必须在他们的 FB 设置中手动撤销应用程序的访问权限,这显然是不可能的。

那么我怎样才能将所需的电子邮件权限作为我的应用程序/网站的一部分?

老实说,我无法在不挠头的情况下阅读整个 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';
}
}

最佳答案

在继续您的应用程序逻辑之前,您应该检查收到的访问 token 。此处描述了如何执行此操作:

https://developers.facebook.com/docs/facebook-login/permissions/v2.0#checking

如果您随后发现用户没有授予 email 权限,您可以按照此处所述将他重新发送到权限对话框:

https://developers.facebook.com/docs/facebook-login/permissions/v2.0#handling

引用:

If someone has declined a permission for your app, the login dialog won't let your app re-request the permission unless you pass auth_type=rerequest along with your request.

关于php - 如何在使用 FB 登录名登录/注册用户时需要电子邮件权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23799185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com