facebook graph api returns only name and id for so

2019-01-22 11:35发布

问题:

I've developed a wordpress plugin for social login using facebook. I'm using the facebook graph API /me to retrieve the user details, What my problem is for some websites when installed a facebook login plugin i'm just getting user id and name only

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

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

Array
(
    [id] => 398463877009801
    [email] => something@gmail.com
    [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?

回答1:

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