通过javascript sdk获取facebook用户的电话号码

Getting Phone number from the user of facebook through javascript sdk

本文关键字:用户 电话号码 facebook 获取 javascript sdk 通过      更新时间:2023-09-26

我需要获得通过facebook登录我的webapp的用户的电子邮件地址。一切都很好,但有些人用电话号码而不是电子邮件地址登录他们的facebook账户。我需要得到谁使用电话号码,而不是电子邮件地址的用户的电话号码。我怎么能得到,请找到下面的代码,我已经尝试到目前为止。

<!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>

这是不可能的——API无法访问用户的电话号码。

如果你没有收到电子邮件,但你需要一个-然后你必须要求用户在FB登录后输入一个。(如果你需要通过双重选择来验证它,那么你也必须自己实现。)