Facebook oauth 检索用户电子邮件 [英] Facebook oauth retrieve user Email

查看:32
本文介绍了Facebook oauth 检索用户电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Facebook Javascript SDK 来获取 oauth 令牌并从 FB 检索所有数据:

I am using Facebook Javascript SDK to get oauth token and retrieve all the data from FB:

 function login() {
    FB.api('/me', function (response) {            
        alert('You have successfully logged in, ' + response.name + ", " + response.email + "!");

    });

我检索了所有基本信息(全名、工作、学校、ID..),但没有检索到 EMAIL(响应.email == 未定义)!

I retrieve all basic information (full name, work, school, ID..) but not EMAIL (response.email == undefined) !!

我知道可以在基本信息中访问电子邮件(不要求电子邮件"权限),我该怎么做?

I know it's possible to access email within basic information (not asking for 'email' permissions), how do I do that?

推荐答案

你需要明确的收到邮件如下:

You need get email explicitly as follows:

                    var url = '/me?fields=name,email';
                    FB.api(url, function (response) {
                        alert(response.name);
                        alert(response.email);
                    });

要获取电子邮件地址,需要电子邮件权限.所以代码可能看起来像(还有其他选项,如注册按钮、登录按钮..)

And to get the email address, email permission is needed. So the code might look like (there are other options like Register button, login button..)

            FB.login(function (response) {
                if (response.session) {
                    var url = '/me?fields=name,email';
                    FB.api(url, function (response) {
                        alert(response.name);
                        alert(response.email);
                    });
                }
                else {
                    alert("User did not login successfully");
                }
            }, { scope: 'email' }); /* perms changed to scope */

这篇关于Facebook oauth 检索用户电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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