dopmgo4707 2015-11-16 07:42
浏览 34
已采纳

fb登录中电子邮件的未定义值[重复]

I want to get the users email id from facebook i user java script SDK for getting email id

  <script>

(function(d){
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "https://connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));

     $(document).ready(function() {
     $('#fb_button').click(function() {
     FB._https = (window.location.protocol == "https:"); // Required because FB Javascript SDK tries to submit https to http
    FB.init({appId:"{app_id}", cookie:true, status:true, xfbml:true, oauth:true , version:'v2.5'});
    FB.login(function(response) {

    if (response.authResponse) {
    console.log('Welcome!  Fetching your information.... ');
    console.log(response); // dump complete info
    access_token = response.authResponse.accessToken; //get access token
    user_id = response.authResponse.userID; //get FB UID


    FB.api('/me', function(response) {
        user_email = response.email; //get user email
        alert(user_email);
  });  
  }
  else{
  alert('no response');
  }   
}, {
    scope: 'email'

    });

     });
});


(function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
  //  document.getElementById('fb-root').appendChild(e);
    }());
     </script>

it returns response but undefined value for alert i copy paste the same code in another site with different app_id it returns the email id for same user. i also tried PHP SDK but same result.may be this question is duplicate .but i tried almost all answers of those questions.

Anyone got any idea what's going wrong please?

Thanks in advance

</div>
  • 写回答

1条回答 默认 最新

  • doupang3062 2015-11-16 08:57
    关注

    "Declarative Fields" is what you need, see the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4

    For example:

    FB.api('/me', {fields: 'name,email'}, function(response) {
        user_email = response.email; //get user email
        alert(user_email);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog