我必须创建一个网站才能使用Facebook登录。有道理能够向他们发送电子邮件,但我无法从Facebook获取电子邮件地址。Facebook API获取电子邮件地址
我完全遵循https://developers.facebook.com/docs/facebook-login/getting-started-web/ 的指示我在FB.login中添加了{scope:email}。
如何使用Facebook API获取电子邮件地址?
我的代码现在:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'app', // App ID
channelUrl : '//domain.COM/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
FB.api('/me', function(response) {
console.log(response);
});
} else if (response.status === 'not_authorized') {
FB.login(function(response) {},{scope: 'email'});
} else {
FB.login(function(response) {}, {scope: 'email'});
}
});
};
// Load the SDK asynchronously
(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));
</script>
<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
这是我没有电子邮件对象存在问题。在回应中,我只有基本知识。 – Alqin
在连接了response.status的情况下console.log(response)的输出是什么? –