使用Facebook API获取未定义的用户电子邮件 [英] Getting user email undefined using facebook api
本文介绍了使用Facebook API获取未定义的用户电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取用户ID,名称,电子邮件。获取ID和名称,但不获取电子邮件。
我有以下代码:
I am trying to get user id, name, email. Getting id and name but not email. I have this code:
<html>
<head></head>
body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxx',
status : true,
cookie : true,
xfbml : true
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
});
};
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
FB.api('/me', function(response) {
console.log(response.name + '---'+response.email);
});
}
</script>
<fb:login-button show-faces="true" width="200" max-rows="1" scope="public_profile,email"></fb:login-button>
</body>
</html>
输出为:
名字的姓氏---未定义
FirstName LastName---undefined
为什么电子邮件未定义?我也想获得所有可能的信息。
Why email is undefined? I also want to get all informations possible to get. How?
推荐答案
我尝试用我的测试应用程序进行编码,但确实遇到了同样的问题。要解决该问题,我已经尝试过此方法,并且也可以获取电子邮件和全名。
I have tried you code with my test app and I did get the same issue. To fix that issue I have tried this and I am able to get email and full name as well.
替换为-
FB.api('/me?fields=name,email', function(response) {
console.log(response.name + '---'+response.email);
});
这篇关于使用Facebook API获取未定义的用户电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文