Reputation: 3849
I am trying to use Facebook connect in Yii framework.
The problem is I want to access user's email address and $facebook->api('/me') is returning NULL.
How to fix that problem?
Here is my code:
<?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;
Upvotes: 2
Views: 1325
Reputation: 39399
The line:
$d["user_info"] = $facebook->api('/' . $user);
Looks wrong to me. I don’t know what data type $user
would be; I’d just use $facebook->api('/me');
and that will give you the profile of the currently logged in and authenticated user.
Upvotes: 2