我正在尝试使用 fb graph api 2.10 版获取用户详细信息,但根本无法获取电子邮件地址。我尝试在 google 中搜索,但没有得到 2.10 的任何答案。
我的代码如下:
require 'src/Facebook/autoload.php';
$fb = new \Facebook\Facebook([
'app_id' => 'xxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.9',
// 'default_access_token' => 'qRkpJ79uoLmP6EU649rXAx4bZHs', // optional
]);
$helper = $fb->getRedirectLoginHelper();
// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
// $helper = $fb->getRedirectLoginHelper();
// $helper = $fb->getJavaScriptHelper();
// $helper = $fb->getCanvasHelper();
// $helper = $fb->getPageTabHelper();
try {
// Get the \Facebook\GraphNodes\GraphUser object for the current user.
// If you provided a 'default_access_token', the '{access-token}' is optional.
$response = $fb->get('/me?fields=id,email,first_name,last_name,website,work', 'xxxxxxxxxxxxxxxxxxxx');
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$me = $response->getGraphUser();
print_r($me);