2012-12-17 93 views
0

我不知道我的脚本发生了什么,它工作得很好,然后它突然不返回电子邮件(返回未定义),但名字,姓氏和用户名工作正常。facebook登录脚本停止工作

这里是代码

<script type="text/javascript"> 


     // initialize the library with the API key 

     FB.init({ appId: 'XXXXXXXXXX',status: true, cookie: true, xfbml: true, oauth: true }); 

     function login() { 
      FB.login(function (response) { 
       if (response.authResponse) { 
        console.log('Welcome! Fetching your information.... '); 

        FB.api('/me', function (response) { 

         console.log('Good to see you, ' + response.name + '.email :' + response.email); 
         console.log('Good to see you, ' + ",gender:" + response.gender + "another : " + response.first_name); 
         console.log('Good to see you, ' + response.username + '.last_name :' + response.last_name); 
        // console.log('Good to see you, ' + response); 
        }, { scope: 'email' }); 
       } else { 
        console.log('User cancelled login or did not fully authorize.'); 
       } 
      }); 
     } 
    </script> 

,虽然我还没有改变任何东西,这可能是错了吗?

+0

我忘了提及,当我登录到Facebook时,它只要求基本的信息访问权限,根本不提电子邮件。 –

回答

2

要获得电子邮件,需要将{ scope: 'email' }传递给FB.login,而不是作为FB.api的参数。

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

它工作得很好,谢谢。 –