0

I've been using Facebook JS SDK combined with PHP SDK v4 to authenticate users via Facebook. The Facebook app I've been using is on version 2.3.

Now, I needed to create a new FB app for another site - the current version of the newly created FB app is 2.9. When I use the same code (using PHP SDK v4), suddenly, I am unable to get the authenticated user's email address, even though I still can do it when I switch to the old FB app. Also, the response from the 2.9 app has only 2 properties in it (id and full name), while the 2.3 one carries way more information.

I saw this post, however the user I'm trying to log in with:

  • has granted all permissions to the Facebook app,
  • registered with an email (not a phone number) on Facebook, and
  • validated their email address.

TL;DR

Authenticating a user via Facebook app v2.3 returns their email address, but a new Facebook app of v2.9 - doesn't. PHP SDK version I use: 4.


Any idea what might have changed on Facebook side? Do I have to upgrade the SDK?

Community
  • 1
  • 1
lesssugar
  • 15,486
  • 18
  • 65
  • 115

1 Answers1

2

Since the v2.4, you have to specify the fields you're looking for in your request. And for all the different API calls, not only users.

In the past, responses from Graph API calls returned a set of default fields. In order to reduce payload size and improve latency on mobile networks, we have reduced the number of default fields returned for most Graph API calls. In v2.4 you will need to declaratively list the response fields for your calls.

Tips: If you want to have the list of all available fields, you need to do a query like this:

$facebook->api('/me?metadata=1');

And then you'll have to do something like this:

$facebook->api('/me?fields=email,first_name,last_name');

SamHecquet
  • 1,818
  • 4
  • 19
  • 26