简体   繁体   English

facebook登录脚本停止工作

[英]facebook login script stopped working

I dont know what happened to my script, it was working great, then it suddenly doesnt return email (returns undefined), but the firstname, lastname and username work fine. 我不知道我的脚本发生了什么,它工作得很好,然后它突然没有返回电子邮件(返回undefined),但firstname,lastname和username工作正常。

here is the code 这是代码

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

I havent changed anything though, what could be wrong ? 我没有改变任何东西,可能有什么不对?

To get the email, { scope: 'email' } needs to be be passed to FB.login , not as a parameter to FB.api . 要获取电子邮件,需要将{ scope: 'email' }传递给FB.login ,而不是作为FB.api的参数。

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

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

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