我正在尝试在 Yii 框架中使用 Facebook 连接。
问题是我想访问用户的电子邮件地址,而 $facebook->api('/me') 返回 NULL。
如何解决这个问题?
这是我的代码:
<?php
Yii::import("ext.fconnect.*");
$app_id = "xxx";
$app_secret = "xxxx";
Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user_profile = $e;
$user = NULL;
}
}
if ($user) {
$d["logoutUrl"] = $facebook->getLogoutUrl(array(
'fblogout' => 'true',
'next' => $this->createAbsoluteUrl("main/signout")
));
$d["user_info"] = $facebook->api('/' . $user);
} else {
$d["loginUrl"] = $facebook->getLoginUrl(array(
'scope' => 'email, read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
'redirect_uri' => $this->request->hostInfo . $this->request->url,
));
}
$d["user"] = $user;
$d["userprofile"] = $user_profile;