使用facebook javascript sdk访问登录的用户电子邮件

时间:2013-09-01 08:26:35

标签: javascript facebook facebook-graph-api facebook-javascript-sdk

我已尝试使用javascritp sdk教程使用facebook按钮进行登录,但我在电子邮件字段中一直“未定义”,并且应用程序不会请求访问电子邮件。任何想法我应该做什么不同? 这是我的代码......

     <script>


 window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '92',                        // App ID from the app dashboard
      channelUrl : '//om/fd/channel.php', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      cookie     : true,
      oauth:true,
      xfbml      : true                                  // Look for social plugins on the page
    });
  FB.Event.subscribe('auth.authResponseChange', function(response) {
      serverLogin();
    } else if (response.status === 'not_authorized') {
    FB.login(function(response){scope:'email'});
    } else {

FB.login(function(response){scope:'email'});
    }
  });
  };

  function serverLogin() {

    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me?fields=email,name', function(response) {
      console.log('Good to see you, ' + response.name + '.'+response.email);
      alert('Good to see you, ' + response.name + '.'+response.email);
    });
    //FB.logout();
  }
  // Load the SDK asynchronously

</script>
       <fb:login-button show-faces="false" width="100" max-rows="1"></fb:login-button>

名称已正确返回,但电子邮件未定义....

1 个答案:

答案 0 :(得分:0)

scope参数中定义权限,如:

<fb:login-button show-faces="false" scope="email" width="100" max-rows="1"></fb:login-button>