[英]Get email from Facebook User
我正在尝试使用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>');
}
?>
我尝试了上面的方法,但是没有用。 我尝试通过登录名获得扩展权限,但是没有运气,不确定我是否做对了。
我收到错误“未定义索引:电子邮件”。
我该如何解决?
要指定所需的权限,您需要使用称为scope
的键将它们传递到传递给getLoginUrl
函数的数组中。
$login_url = $facebook->getLoginUrl(array(
'scope' => 'email'
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.