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

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

问题描述

我似乎不需要提供电子邮件权限。

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

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

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#handling

报价:


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

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

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