电子邮件范围无法在FB登录中使用 [英] Email scope is not working which is used in FB Login

查看:108
本文介绍了电子邮件范围无法在FB登录中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的网站上使用FB登录,并需要获取用户信息(电子邮件,public_profile,出生日期和地点)。但是在登录后我只获得了用户名和facebookId。代码:

I try to use FB Login on my website and need to get user informations ( email, public_profile, date of birth and location ). But after logged in only name and facebookId of user that I got. Codes :

<img src="" alt="" onclick="fblogin();"/>

Javascript part:

Javascript part :

function statusChangeCallback(response) {
        console.log('statusChangeCallback');
        console.log(response);
        // The response object is returned with a status field that lets the
        // app know the current login status of the person.
        // Full docs on the response object can be found in the documentation
        // for FB.getLoginStatus().
        if (response.status === 'connected') {
            // Logged into your app and Facebook.
            testAPI();
        } else if (response.status === 'not_authorized') {
            // The person is logged into Facebook, but not your app.
            document.getElementById('status').innerHTML = 'Please log ' +
              'into this app.';
        } else {
            // The person is not logged into Facebook, so we're not sure if
            // they are logged into this app or not.
            document.getElementById('status').innerHTML = 'Please log ' +
              'into Facebook.';
        }
    }

    // This is called with the results from from FB.getLoginStatus().
    function checkLoginState() {
        FB.getLoginStatus(function (response) {
            statusChangeCallback(response);
        });
    }



    function fblogin()
    {
        checkLoginState();
        FB.login(function (response) {
            if (response.authResponse) {
                console.log('Bilgiler Alınıyor');
                FB.api('/me', function (response) {

                    console.log(JSON.stringify(response));
                });
            } else {
                console.log('User cancelled login or did not fully authorize.');
            }
        }, { scope: 'user_about_me,email,public_profile' });
    }


    window.fbAsyncInit = function () {
        FB.init({
            appId: '{app-id}',
            xfbml: true,
            version: 'v2.4'
        });

        FB.getLoginStatus(function (response) {
            if (response.status === 'connected') {
                console.log(response.authResponse.accessToken);
            }
        });
    };

    (function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

JSON结果:

{"name":"Name Surname","id":"xxxxxxxxxxxxxxxxx"}

没有电子邮件或任何其他信息。

No email or any other informations.

推荐答案

这是一个众所周知的问题,搜索声明字段更改日志: https://developers.facebook.com/docs/apps/changelog#v2_4

That is a well known issue, search for "Declarative Fields" in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4

例如:

FB.api('/me?fields=id,name,email', ...

我相信你也可以这样做:

I believe you can also do it like this:

FB.api('/me', {fields: 'id,name,email'}, ...

顺便说一下,确保你知道异步JavaScript如何工作,你在FB.login之前调用checkLoginState(),但FB .getLoginStatus不会立即返回一些内容而你总是调用FB.login。这是一篇关于如何使用FB.login的文章和FB.getLoginStatus以适当的方式: http://www.devils-heaven.com/facebook- javascript-sdk-login /

Btw, make sure you know how asynchronous JavaScript works, you are calling checkLoginState() right before FB.login, but FB.getLoginStatus does not return something immediately and you are always calling FB.login. Here´s an article about how to use FB.login and FB.getLoginStatus in a proper way: http://www.devils-heaven.com/facebook-javascript-sdk-login/

这篇关于电子邮件范围无法在FB登录中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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