使用FB登录登录/注册用户时如何使电子邮件权限? [英] How to make email permission required when logging in/signing up a user using the FB login?

查看:132
本文介绍了使用FB登录登录/注册用户时如何使电子邮件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使电子邮件获得许可。

I can't seem to make the email permission required.

如果用户取消启动FB登录的电子邮件,我的代码会中断。当我尝试编写围绕这个问题的代码(尝试提醒用户接受电子邮件权限必要时),它将无法正常工作;用户必须在他们的FB设置中手动撤销App的访问权限,这显然是不成问题的。

If a user unticks the email udring the FB login, my code breaks down. And when I try writing code around this problem (try to alert the user to accept the email permission requisite.), it won't work; the user would have to revoke the App's access manually in their FB settings, and that is obviously out of the question.

那么如何将电子邮件权限作为一部分我的应用程序/网站?

So how can I make the email permission required as part of my app/website?

Tbh,我无法通过整个Facebook API文档阅读,而不用抓住我的头。

Tbh, I couldn't read through the entire Facebook API docs without scratching my head through it.

这是我目前所在的:

    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';
        }
    }


推荐答案

你应该在继续使用应用程序逻辑之前检查接收到的访问令牌。如何做到这一点在这里描述:

You should check the received Access Token before you continue with your application logic. How to do this is described here:

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

如果您认识到用户没有给出电子邮件权限,则可以按照如下所述重新发送到权限对话框:

If you then recognize that the User didn't give the email permission, you can resend him to the permission dialog as described here:

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

引用:


如果有人拒绝了您的应用的权限,登录对话框
将不会让您的应用重新请求权限,除非您通过
auth_type = rerequest 以及您的请求。

这篇关于使用FB登录登录/注册用户时如何使电子邮件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆