12

I am trying to login to my website using my Facebook account but Facebook is giving name and id only that is not enough to login user. Before I was getting full information like firstname, lastname, email etc.

Data provided by facebook now:

stdClass Object
(
    [name] => FName LName
    [id] => 236189327864097
)

I am using Oauth v2.0 to login users through Facebook to my website.

vhu
  • 12,244
  • 11
  • 38
  • 48
Wolfack
  • 2,667
  • 1
  • 26
  • 50

4 Answers4

15

Looks like you're using v2.4 of the Graph API. See

Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

To get an idea how to use the so-called field expansion, have a look at

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • @RaghubendraSingh Yes, **if** you're using v2.4. – Tobi Jul 29 '15 at 07:46
  • added fields in the url called using CallAPI function and the desired results. Relaxed now. – Wolfack Jul 29 '15 at 07:55
  • Thanks for this. I would also suggest that you edit your answer to add this link aiming the phonegap facebook plugin users: https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1092 –  Sep 09 '15 at 22:06
9
FB.api('/me?fields=first_name, last_name, picture, email', function(response) {
          console.log(response);
          document.getElementById('status').innerHTML =
            'Thanks for logging in, ' + response.first_name + '!';
        });

This worked for me. Pass email after /me?fields= in FB.api request.

Swati Pardeshi
  • 599
  • 9
  • 12
1

If you using PHP, you need to read also this article:

https://developers.facebook.com/docs/facebook-login/permissions/v2.4

Basically, Fb says about email that

Note, even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty.

sineverba
  • 5,059
  • 7
  • 39
  • 84
1

Pass by parameters the fields that you looking for:

var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=birthday,email,name,id"), null, eventArgs.Account);
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68