Francesco Francesco - 6 months ago 95
PHP Question

Facebook PHP SDK Age Range

I'm creating a facebook application that allows users to register at my site using data from facebook, then I need to retrieve these data.

The code I wrote is as follows:

$request = new FacebookRequest(
$session,
'GET',
'/me'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
$user = $response->getGraphObject(GraphUser::className());


And then I get some information with:

echo "Name: " . $graphObject->getProperty('name');
echo "<br/>";
echo "Email: " . $graphObject->getProperty('email');


etc.

The problem is that I don't know how to get the age range, because if I try

echo "Age range: " . $graphObject->getProperty('age_range');


or

echo "Age range: " . $graphObject->getProperty('agerange');


It returns an empty space, without providing any data.

So, how can I retrieve age range infos?

Answer

age_range is not a default field so you will have to ask for it using /me?fields=age_range