如何从fb库获取电子邮件

时间:2016-08-12 06:09:26

标签: php facebook

  

如何从facebook api获取电子邮件和联系方式。 $ graphObject 仅提供   名称和ID。怎么解决这个?

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 个答案:

答案 0 :(得分:0)

这将是正确的API调用:

/me?fields=name,email

从Graph API的v2.4开始,您必须指定字段。它被称为&#34;声明字段&#34;。