Facebook登录:强制要求发送电子邮件

时间:2015-06-17 07:33:41

标签: javascript html facebook login facebook-login

我们正在使用facebook登录我们的网站。
我们需要电子邮件作为强制许可。如果用户未授予电子邮件权限,则对话框应发出alert()消息,说明“请授予电子邮件权限”并重复。

我在很少的购物网站看过这个功能。下面的代码工作正常,但没有我提到的功能。
需要帮助。

  window.fbAsyncInit = function () {
            FB.init({
                appId: 'MY APP ID',
                oauth: true,
                status: false, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true // parse XFBML
             });
    };

    function fb_login() {
        FB.login(function (response) {
            if (response.authResponse) {
                access_token = response.authResponse.accessToken; //get access token
                user_id = response.authResponse.userID; //get FB UID

                FB.api('/me', function (response) {
                    // you can store this data into your database
                    alert(response.email);
                });

            }
        }, {
            scope: 'email'
        });
    }
    (function () {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    } ());

HTML正文中的某个地方。

<div class="span"><a onclick="fb_login();"><img src="css/images/facebook.png" alt=""/><sm>Sign In with Facebook</sm><div class="clear"></div></a></div>	

1 个答案:

答案 0 :(得分:2)

看看

尤其是第一个链接的“处理遗漏权限”部分。

  

当应用请求权限时,人们可能会完全拒绝这些权限,不会完全授予这些权限,也不会在以后更改这些权限。为了提供出色的体验,应该构建应用程序来处理这些情况。

     
      
  • 首先,应用应该能够处理已请求但未授予的任何权限:
  •   
  • 在尝试使用需要它们的API之前检查授予的权限。   检测在没有正确权限的情况下发出API请求时返回的权限错误。
  •