facebook api不返回电子邮件
我正在尝试使用facebook api返回用户电子邮件地址。前几天还不错,但今天停止了工作,不知道为什么 所以首先我得到了访问令牌:facebook api不返回电子邮件,facebook,facebook-graph-api,facebook-javascript-sdk,Facebook,Facebook Graph Api,Facebook Javascript Sdk,我正在尝试使用facebook api返回用户电子邮件地址。前几天还不错,但今天停止了工作,不知道为什么 所以首先我得到了访问令牌: FB.login(response => { if (response.authResponse) { resolve(response.authResponse.accessToken); } else { reject({ error: 'User cancelled login or did no
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);
});
但是我只得到名字和姓氏的数据。没有电子邮件
另外,当我请求权限时,它会给我授予的电子邮件,但正如我所说的,电子邮件不会被返回
FB.api('/me/permissions', function(response) {
console.log(response);
});
有人知道问题出在哪里吗
顺便说一句:我使用的是API v2.4
FB.api('/me?fields=email,name', function(response) { /* stuff here */ });
尝试将返回字段添加到请求中。可能的原因是用户未验证电子邮件。尝试与另一个具有已验证电子邮件的用户联系,以确保这不是问题所在
另请参见我知道这是一个老问题,但如果有人仍在寻找答案,则以下解决方法对我有效 您需要在scope
scope=“public\u profile,email”
中添加电子邮件
我使用了一个承诺,将{scope:'email'}添加到初始请求中,然后在fb.api字段中包含'email'
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);
});
}
});
我花了很多时间试图弄清楚为什么FacebookLoginASPnetWebForms Asp.Net应用程序()上不返回电子邮件 多亏了N Nem上面的帖子(谢谢!),我让它工作起来了 打开Default.aspx.cs 在HyperLink1.NaviagteUrl中,添加查询字符串参数:&scope=public\u profile,email
HyperLink1.NavigateUrl = "https://www.facebook.com/v2.4/dialog/oauth/?client_id=" + ConfigurationManager.AppSettings["FacebookAppId"] + "&redirect_uri=http://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/account/user.aspx&response_type=code&state=1&scope=public_profile,email";
我还必须修复一些bug来正确解析访问令牌
这一次,电子邮件地址可用!我希望这有帮助?N上面的Nem已为我修复。代码正确,但缺少登录按钮上的作用域。我使用的代码如下
function statusChangeCallback(response){
if(response.status === 'connected'){
registerUser(response);
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
function registerUser(statusResponse){
let userId = statusResponse.authResponse.userID;
FB.api('/'+userId+'/?fields=id,email,first_name,last_name',function(response){
if(response && !response.error){
console.log(response);
}
});
}
这是一个有点老的帖子,但我正在分享对我有用的解决方案 FB登录SDK版本:v6.0 首先,确保用户(出于测试目的是您)拥有有效/已验证的电子邮件。请参阅下面的代码
FB.login(response => {
// your code
}, {
scope: 'public_profile,email',
return_scopes: true,
auth_type: 'rerequest'
});
以及获取用户详细信息
const response = await axios({
method: 'get',
url: 'https://graph.facebook.com/v6.0/me?fields=id,name,email&access_token=ACCESS_TOKEN&pretty=0&sdk=joey&suppress_http_code=1'
}))
我已经添加了参数字段=id、name、email,如果您正确设置了所有代码,但仍然没有从API收到电子邮件。用户可能没有绑定到帐户的电子邮件或未经用户确认的电子邮件。首先在Graph API Explorer中尝试该请求,使用您的应用程序id和JS使用的相同访问令牌(应包含在
响应
对象中,因此将其记录到控制台并从那里复制和粘贴),请确保用户在其帐户中设置了有效的电子邮件地址,并且该地址已被验证。这是针对您的所有用户,还是仅针对一个或几个用户?就像CBroe提到的;可能是有人从他们的个人资料中删除了他们的电子邮件。不是这样,建议的方法是增加一个参数:-另外,他得到了其他字段,只有电子邮件丢失。是的,当然电子邮件丢失了任何解决方案。这个解决方案对我有效,将字段作为参数传递是不一致的。我也必须这样做。我指定了适当的作用域,但默认情况下,空的“/me”只返回id和name。Facebook文档是不可靠的,fb不必费心确保它按照文档记录的方式工作,或者在所有文档中都不一致。这就是我的原因。谢谢你指出这一点:)我毫不怀疑它是有效的,但这在developers.facebook.com的任何地方都有记录吗?
const response = await axios({
method: 'get',
url: 'https://graph.facebook.com/v6.0/me?fields=id,name,email&access_token=ACCESS_TOKEN&pretty=0&sdk=joey&suppress_http_code=1'