facebook api没有返回电子邮件

问题描述:

我想用facebook api返回用户的电子邮件地址。几天前它工作正常,但今天停止工作,不知道为什么。facebook api没有返回电子邮件

所以首先我得到的访问令牌:

FB.login(response => { 
    if (response.authResponse) { 
     resolve(response.authResponse.accessToken); 
    } else { 
     reject({ 
     error: 'User cancelled login or did not fully authorize.' 
     }); 
    } 
    }, { 
    scope: 'public_profile,email' 
    }); 

然后我会试图获取用户数据

FB.api('/me', {fields: 'first_name,last_name,email'}, function(response) { 
    console.log(response); 
}); 

,但我只得到First_Name和Last_Name数据。没有电子邮件。

另外,当我要求权限,它给了我电子邮件,如我所说,电子邮件不返回。

FB.api('/me/permissions', function(response) { 
    console.log(response); 
}); 

有没有人知道可能是什么问题?

顺便说一句:我正在使用API​​ v2.4。

+0

尝试在图形API浏览器的请求首先,使用您的应用ID和相同的访问令牌的JS使用(应包含在'response'对象,因此其记录到控制台,将其复制并从那里粘贴。 )另外,请确保用户在其帐户中设置了有效的电子邮件地址,并确认其已被验证。 – CBroe

+0

这是发生在你的所有用户,还是仅仅一个或几个?像CBroe提到的一样;可能是有人从他们的个人资料中删除了他们的电子邮件。 – Roemer

FB.api('/me?fields=email,name', function(response) { /* stuff here */ }); 

尝试将您的返回字段添加到您的请求。

+1

这不是它,推荐的方式将是一个额外的参数:https://developers.facebook.com/docs/javascript/reference/FB.api - 也,他得到其他领域,只有电子邮件丢失。 – luschn

+0

是的,绝对是电子邮件缺少任何解决方案请 –

+0

此解决方案为我工作,传递领域作为参数不一致。 –

可能的原因是用户未验证电子邮件。尝试与另一个用户验证电子邮件,以确保这不是问题。

又见this answer

我知道这不过是老问题,如果有人仍然seraching答案,然后下面的解决方法为我工作。

您需要在范围scope="public_profile,email"中添加电子邮件。

<fb:login-button scope="public_profile,email" autologoutlink="false" onlogin="OnRequestPermission();"></fb:login-button> 

我使它工作使用一个承诺并加入{范围:“电子邮件”}的初始请求,那么,包括在fb.api字段“电子邮件”。

fb.login({scope:'email'}).then(function (resp) { 
    if (resp.status === 'connected') { 
     fb.api('/me', 'get', {fields:'id,email,first_name,gender,...'}).then(function (FbUserData) { 
      console.log(FbUserData); 
     }); 
    } 
});