我正在使用facebook sdk让用户登录我的网站。这段代码一直工作到今天,实际上它返回(从现在开始)一个引用最后一行的错误。
//FACEBOOK SDK CODE
//--------------------------------------------------------------
require 'facebookSDK/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
// 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;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook->getLoginUrl();
header('location: '.$loginUrl);
exit;
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
//----------------------------------------------------------------
$facebook_id=$user_profile['id'];
$facebook_name=$user_profile['name'];
$facebook_email=$user_profile['email'];
未定义的索引'email'。 我不知道该怎么做!它从现在开始工作...... 我需要获取用户的电子邮件,'name'和'id'参数都可以,但不是'email'。
我该如何解决?
答案 0 :(得分:0)
Facebook已更新其api
将此行更改为 $ user_profile = $ facebook-> api(' / me?fields = email');