javascript Facebook Graph API 不会返回电子邮件地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16630972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Graph API won't return email address
提问by joao Beno
Edit: Not Duplicate, because:
编辑:不重复,因为:
- I have the permission
- Debugged the token
- Code works with test user
- 我有权限
- 调试令牌
- 代码适用于测试用户
Please don't mark as duplicate without reading.
请不要在未阅读的情况下标记为重复。
I'm trying to get the user e-mail address, but i don't get it. On graph api explorer, when i hit send, email field becomes grayed and says that:
我正在尝试获取用户的电子邮件地址,但我不知道。在图形 API 资源管理器上,当我点击发送时,电子邮件字段变为灰色并显示:
field is empty or disallowed by access token
字段为空或被访问令牌禁止
But when I debug the token it has email permission granted
但是当我调试令牌时,它授予了电子邮件权限
My profile has an e-mail address.
我的个人资料有一个电子邮件地址。
Update: I tried https://developers.facebook.com/tools/console/. My profile returns nothing, even on another computer. But the same code returns the email, name and uid of another account.
更新:我试过https://developers.facebook.com/tools/console/。即使在另一台计算机上,我的个人资料也没有任何返回。但相同的代码返回另一个帐户的电子邮件、名称和 uid。
Code:
代码:
<fb:login-button scope="email">
Grant Permissions to make more examples work
</fb:login-button>
<button onclick="doPost()">Post to Stream</button>
<script>
function userData() {
FB.api('/me?fields=name,email', Log.info.bind('/me callback'));
};
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
userData();
}
});
</script>
It is possible to lockdown you e-mail so no one can has it? Even when i grant permission?
是否可以锁定您的电子邮件,让任何人都无法拥有它?即使我授予许可?
采纳答案by joao Beno
After i got my bug report marked as duplicate, and i read all posts and links there, i got what caused this problem for me and how to fix.
在我将错误报告标记为重复并阅读那里的所有帖子和链接后,我了解了导致此问题的原因以及如何解决。
The ProblemFacebook seems to sometimes forget what your primary e-mail is on the graph API (But it still there in the preferences.)
问题Facebook 似乎有时会忘记您在图形 API 上的主要电子邮件是什么(但它仍然存在于首选项中。)
SolutionThe user affected must remove the e-mail, save settings, then re-add the address, re-confirm, then make it primary. This fixed my account both on my sandbox app, and other apps where Facebook login don't used to work.
解决方案受影响的用户必须删除电子邮件,保存设置,然后重新添加地址,重新确认,然后将其设为主要。这在我的沙盒应用程序和其他 Facebook 登录不可用的应用程序上修复了我的帐户。
回答by Miere
The Marcus' answerleads me to the real problem I was facing.
Marcus 的回答将我引向了我面临的真正问题。
Debugging with the Facebook Explorer tool I was able to figure out that I should set the email scopeat the FB.api()
method after a successful login.
使用 Facebook Explorer 工具进行调试后,我发现我应该在成功登录后在方法中设置电子邮件范围FB.api()
。
FB.login(function(response) {
if (response.status === 'connected'){
FB.api('/me?fields=id,email,name', function(data) {
console.log( data.email ) // it will not be null ;)
})
}, {scope: 'email'});
It is not quite clear at the Quickstartguide and I hope it helps someone else, too.
快速入门指南中不太清楚,我希望它也能帮助其他人。
回答by ozba
I had the same problem and I think I found out why: If the user has an unconfirmed email in Facebook (i.e. Facebook sent him a validation mail to his email address but he didn't respond) Facebook WILL NOT pass that email to your app even if he gave you the email permissions (!!!).
我遇到了同样的问题,我想我找到了原因:如果用户在 Facebook 中有一封未经确认的电子邮件(即 Facebook 向他的电子邮件地址发送了一封验证邮件,但他没有回复)Facebook 不会将该电子邮件传递给您的应用即使他给了你电子邮件权限(!!!)。
So what I did is use his Facebook email if he has a user name (i.e. [email protected]).
所以我所做的是使用他的 Facebook 电子邮件,如果他有用户名(即 [email protected])。
回答by Alin Razvan
New facebook graph requires scopes added in the /me request as follow:
新的 facebook 图表需要在 /me 请求中添加范围,如下所示:
/me?fields=email,birthday,location,locale,age_range,currency,first_name,last_name,name_format,gender&access_token=
/me?fields=email,birthday,location,locale,age_range,currency,first_name,last_name,name_format,gender&access_token=
回答by Sayed
I had the same issue while I was developing the fb login button for my site. I had even setup permissions for my app here:
我在为我的网站开发 fb 登录按钮时遇到了同样的问题。我什至在这里为我的应用设置了权限:
https://developers.facebook.com/apps/<my-app-ID>/permissions
and it was working fine for certain initial cases, that is, it was giving email (i tested it on my own account and it was giving my email). Then suddenly it started to reflect no email at all. After two hours of browsing, I figured it out that there was an issue with the access token as when I went on this link:
它在某些初始情况下运行良好,也就是说,它正在发送电子邮件(我在自己的帐户上对其进行了测试,并且它正在发送我的电子邮件)。然后突然它开始反映没有电子邮件。浏览两个小时后,我发现访问令牌存在问题,就像我访问此链接时一样:
https://developers.facebook.com/tools/explorer/<your-fb-id>/?method=GET&path=100002451127858%3Ffields%3Did%2Cemail
Update your-fb-id with your id and go to the above link. Click on 'Get Access Token'. In the tab that opens up, click on 'Extended Permissions' and in that, choose 'email' and submit. Now, test your query again. It'll definitely work, on the console as well as your website. Cheers! :)
用您的 id 更新 your-fb-id 并转到上面的链接。单击“获取访问令牌”。在打开的选项卡中,单击“扩展权限”,然后选择“电子邮件”并提交。现在,再次测试您的查询。它肯定会在控制台和您的网站上工作。干杯! :)
回答by spence0021
This is a known bug. If the user does not have any email address set to primary, the query will return null for email. Set the email address for your account to primary https://www.facebook.com/settings?tab=account§ion=email&viewand then try.
这是一个已知的错误。如果用户没有将任何电子邮件地址设置为主要地址,则查询将为电子邮件返回 null。将您帐户的电子邮件地址设置为主要https://www.facebook.com/settings?tab=account§ion=email&view,然后尝试。
Source: https://developers.facebook.com/bugs/298946933534016/