简体   繁体   English

使用Facebook JavaScript Java SDK访问已登录的用户电子邮件

[英]Accessing logged in user email using facebook javascript sdk

I have tried using the javascritp sdk tutorial to make a login using facebook button, but I keep getting "undefined" in the email field, and the app doesn't request access to email..Any ideas what I should do differently? 我曾尝试使用javascritp sdk教程使用Facebook按钮进行登录,但是我在电子邮件字段中不断收到“未定义”,并且该应用程序不请求访问电子邮件。.有什么想法我应该做些不同的事情吗? this is my code... 这是我的代码...

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

name is returned correctly, but email is undefined.... 名称正确返回,但电子邮件未定义...。

scope参数中定义权限,就像:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM