July 25, 2013

Cannot extract information like user's email address from facebook connect

Starx’s Question:

I am trying to use simple Facebook Connect to login users on a website. I am using most basic form of the code to do this:

FB.getLoginStatus(function(response) {
  if (response.status == 'connected') {
    getCurrentUserInfo(response)
  } else {
    FB.login(function(response) {
      if (response.authResponse){
        getCurrentUserInfo(response)
      } else {
        console.log('Auth cancelled.')
      }
    }, { scope: 'email' });

  }
});

function getCurrentUserInfo() {
  FB.api('/me', function(userInfo) {
    console.log(userInfo);
  });
};

I get the basic information only but I do not get any email. I have also set the permission settings on the application too.

Application permission Settings

I test the code using my facebook account. I can connect successfully but I cannot see my email address and my settings for my email is also public.

Can I get some help with this?

Ok, Just figured this out. The problem was that the scope was somehow not being passed to the login function.

All I had to do was modify the fbml code for the login button with the scope and it was asking for the email address authorisation.

<fb:login-button show-faces="true" width="200" max-rows="1" scope="email"></fb:login-button>
...

Please fill the form - I will response as fast as I can!