javascript facebook SDK在要求发送电子邮件时返回undefined

时间:2016-12-29 23:38:47

标签: javascript facebook email facebook-javascript-sdk

我是javascript的新手,我正在尝试使用Javascript Facebook SDK为某些用户获取一些数据,我甚至得到了基本数据和图像URL,但是当我要求发送电子邮件时,它返回undefined,尽管我在下面的代码中询问了电子邮件权限,任何人都可以向我提供帮助吗?

如代码中所示,我将电子邮件作为字段发送但没有结果

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <link rel="stylesheet" href="">
</head>
<body>
  <script>
    // initialize and setup facebook js sdk
    window.fbAsyncInit = function() {
        FB.init({
          appId      : 'MY-FACEBOOK-ID',
          xfbml      : true,
          version    : 'v2.5'
        });
        FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
            document.getElementById('status').innerHTML = 'We are connected.';

          } else if (response.status === 'not_authorized') {
            document.getElementById('status').innerHTML = 'We are not logged in.'
          } else {
            document.getElementById('status').innerHTML = 'You are not logged into Facebook.';
          }
        });
    };
    (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'));

    // login with facebook with extra permissions
    function login() {
      FB.login(function(response) {
        if (response.status === 'connected') {
            document.getElementById('status').innerHTML = 'response.email';
            document.getElementById('login').style.visibility = 'hidden';
          } else if (response.status === 'not_authorized') {
            document.getElementById('status').innerHTML = 'We are not logged in.';
          } else {
            document.getElementById('status').innerHTML = 'You are not logged into Facebook.';
          }
      }, {scope :'email'});
    }

    // getting basic user info
    function getInfo() {
      FB.api('/me', 'GET', {fields: 'email,first_name,last_name,name,id,picture'}, function(response) {
        document.getElementById('status').innerHTML = response.email;
      });
    }
  </script>

  <div id="status"></div>
  <button onclick="getInfo()">Get Info</button>
  <button onclick="login()" id="login">Login</button>
</body>
</html>

返回回复:

/**/ FB.__globalCallbacks.f21242f12383db8({"first_name":"Div","last_name":"Taha","name":"Div Taha","id":"theIdReturnedForTheAccount","picture":{"data":{"is_silhouette":false,"url":"https:\/\/fb-s-c-a.akamaihd.net\/h-ak-xlf1\/v\/t1.0-1\/p50x50\/15697179_111749685993319_625220539244102507_n.jpg?oh=3b4f267aa215ebe785d184f7b6ad224c&oe=58F0F292&__gda__=1491099489_2a09b4cb01843d6a958f81297eaf294e"}}});

0 个答案:

没有答案