0

我正在尝试使用 Facebook php SDK v 3.2.3访问用户的电子邮件地址

编码:

<?php


 require_once('facebook-php-sdk/src/facebook.php');
// Create our Application instance (replace this with your appId and secret).
$facebook= new Facebook(array(
  'appId' => 'xxxxxxx',
      'secret' => 'xxxxxxxxxxxxxxx',
      'allowSignedRequest' => false,
));

$_REQUEST += $_GET;
$user = $facebook->getUser();

if ($user) {
  try {

 $login_url = $facebook->getLoginUrl(array(
    'req_perms' => 'email'
  ));
  echo 'Please <a href="' . $login_url . '">login.</a>';

    $user_profile = $facebook->api('/me?fields=picture.width(100).height(100),first_name,last_name,username,email');
    echo $user_profile['email'];
    echo $user_profile['username'];

  } catch (FacebookApiException $e) {
    $user = null;
  }
} else {
  die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>');
}

?>

我尝试了上述方法,但没有奏效。我尝试通过登录获得扩展权限,但没有运气,不确定我是否做对了。

我收到错误“未定义的索引:电子邮件”。

我该如何解决?

4

1 回答 1

0

To specify the permissions required, you need to pass them in the array passed to the getLoginUrl function with a key called scope.

$login_url = $facebook->getLoginUrl(array(
    'scope' => 'email'
));
于 2014-01-24T11:38:04.117 回答