facebook登录脚本停止工作

时间:2012-12-17 08:25:36

标签: javascript facebook

我不知道我的脚本发生了什么,它工作得很好,然后它突然没有返回电子邮件(返回undefined),但是firstname,lastname和username工作正常。

这是代码

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

我没有改变任何东西,可能是错的?

1 个答案:

答案 0 :(得分:2)

要收到该电子邮件,我需要将{ scope: 'email' }传递给FB.login,而不是FB.api的参数。

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