0

How to get email and contact from facebook api. $graphObject gives only name and id. how to solve this?

if( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
echo "<pre>";print_r($graphObject); exit;
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FBFULLNAME'] = $fbfullname;
$_SESSION['FBEMAIL'] = $femail;
/* ---- header location after session ----*/
header("Location: index.php?act=fbmobile");
}

1 Answers1

0

This would be the correct API call:

/me?fields=name,email

Since v2.4 of the Graph API, you have to specify the fields. It is called "Declarative Fields".

andyrandy
  • 72,880
  • 8
  • 113
  • 130