Facebook graph API returns only name and id for some websites

15,862

As CBroe already pointed out in the above comment, the Facebook API - newer than version 2.4 - changed the response and the way the requests are being sent.

You have to specify each field you want to be returned from the Graph API within your request.

For example, if you want the fields email and name returned, you must add them inside the request like this:

/me?fields=email,name
Share:
15,862
Jay Maharjan
Author by

Jay Maharjan

WordPress plugin developer.

Updated on July 08, 2022

Comments

  • Jay Maharjan
    Jay Maharjan almost 2 years

    I've developed a WordPress plugin for social login using Facebook. I'm using the Facebook graph API /me to retrieve the user details. My problem is that for some websites, when installed a Facebook login plugin, I'm only getting user ID and name.

    Array
    (
        [name] => John doe
        [id] => 398463877009801
    )
    

    but same code is working well for some websites as well.

    Array
    (
        [id] => 398463877009801
        [email] => [email protected]
        [first_name] => John
        [gender] => male
        [last_name] => Doe
        [link] => https://www.facebook.com/app_scoped_user_id/398463877009801/
        [locale] => en_US
        [name] => John Doe
        [timezone] => 5.45
        [updated_time] => 2015-05-03T11:24:16+0000
        [verified] => 1
    )
    

    What might be the possibilities of the errors for the site that is getting only name and id?

  • Jay Maharjan
    Jay Maharjan almost 9 years
    Hi Razvan Thank you so much for your reply. But I tried already placing the fields values but still i'm not getting what i want. I'm always receving id and name if I place the field attributes or not placing any field attributes. It's so strange behaviour to me because same code is working for most of the sites. Thanks
  • Răzvan
    Răzvan almost 9 years
    Are you using the official php facebook sdk? Can we see some code? Did you ask for the right permissions by specifying the scope?
  • Jay Maharjan
    Jay Maharjan almost 9 years
    I don't know how to send the link of the files here. I'll try to narrate my code [code] $facebook = new Facebook($config); $user = $facebook->getUser(); if ($user){ try {// Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } print_r($user_profile ); [/code]
  • Răzvan
    Răzvan almost 9 years
    First of all upgrade your SDK to this version NEW FACEBOOK SDK, as it seems to me that you are running an outdated version and follow this self-explanatory EXAMPLE. Note the $permissions array.
  • Jay Maharjan
    Jay Maharjan almost 9 years
    I really can't make the new facebook sdk work for me. Can you please show me some examples how to implement these example codes.
  • Jay Maharjan
    Jay Maharjan over 8 years
    Finally I was able to fix the issue after updating the facebook php sdk.
  • Raj
    Raj over 8 years
    Thank You!!!! buddy, I fixed this issue at my end, I used 3rd party plugin to manage the Facebook API. below is my call 'graph.facebook.com/v2.3/…'