我需要在我的网站上加入facebook登录才能注册。我创建了一个Facebook应用程序并登录。我只从facebook获得prfile名称和用户ID。如何从Facebook获取电子邮件和其他用户信息?
这些是我从facebook获得的记录:
数组([姓名] => facebook用户[id] => 92141138733449309036)
<?php
require 'src/facebook.php';
$db = file_get_contents('../../../Bin/Configuration.php');
$exp_db = array();
$exp_db = explode('\'',$db);
// print_r($exp_db);
// exit;
$hostname = $exp_db[1];
$username = $exp_db[3];
$password = $exp_db[5];
$database = $exp_db[7];
$connect = mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($database,$connect) or die(mysql_error());
$facebook = new Facebook(array(
// 'appId' => $recordFB['fb_application_id'],
// 'secret' => $recordFB['fb_application_secret'],
'appId' => '1699756843642082',
'secret' => 'a8aab00a1e1a5bdcdd9d4665c0972637',
'cookie' => true,
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else
{
echo "You are NOT Logged in";
}
if (!$user_profile) {
$loginUrl=$facebook->getLoginUrl(array('canvas'=>1,
'fbconnect' => 0,
'req_perms'=> 'email,user_birthday ,publish_stream',
'next' => CANVAS_PAGE,
'cancel_url' => CANVAS_PAGE));
echo '<fb:redirect url="' . $loginUrl . '" />';
# code...
}else
{
echo "you can use this app";
}
$email=$user_profile['email'];
?>
我无法从Facebook获取其他详细信息。请告诉我从Facebook访问用户详细信息的可能解决方案...提前谢谢。
答案 0 :(得分:0)
搜索&#34;声明字段&#34;在更改日志中:https://developers.facebook.com/docs/apps/changelog#v2_4
如果不指定要获取的字段,则只能获取ID和名称。