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

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

问题描述

  function login(){ 
FB.api('/ me',function(response){
alert('你已成功登录,'+ response.name +',+ response.email +!

});

我检索所有基本信息(全名,工作,学校,ID ..),但不是EMAIL response.email == undefined)!!



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

解决方案

您需要通过以下方式获取电子邮件:

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

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

  FB.login(function回复){
if(response.session){
var url ='/ me?fields = name,email';
FB.api(url,function(response){
alert(response.name);
alert(response.email);
});
}
else {
alert(用户没有登录成功 );
}
},{scope:'email'}); / * perms更改为范围* /


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 + "!");

    });

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天全站免登陆