我需要获取通过Facebook登录我的webapp的用户的电子邮件地址。一切都很好,但有些人使用电话号码而不是电子邮件地址登录他们的fb帐户。我需要获取使用电话号码而不是电子邮件地址的用户的电话号码。我怎么能得到它,请找到我到目前为止尝试的下面的代码。
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
alert("JSON "+JSON.stringify(response));
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
testAPI();
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'xxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.4' // use version 2.4
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email', function(response) {
alert("response "+JSON.stringify(response));
console.log('Successful login for: ' + JSON.stringify(response));
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<!--
Below we include the Login Button social plugin. This button uses
the JavaScript SDK to present a graphical Login button that triggers
the FB.login() function when clicked.
-->
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<div id="status">
</div>
</body>
</html>
答案 0 :(得分:0)
这是不可能的 - API无法访问用户的电话号码。
如果您没有收到电子邮件,但需要一封电子邮件 - 那么您必须要求用户在FB登录后输入一封电子邮件。 (如果你需要通过双重选择来验证它,那么你也必须自己实现它。)