I am working on FB application using the PHP SDK. The implementation seems to be correct and everything seems fine.
The problem I am facing is that some users profiles do not contain an email address. That is wierd because the application asks for this permissions specifically.
Code for this action:
// 1. If we cant get the user, log him in and request permissions if he has deleted/deauthorized or new to app
if (!$fbCurrentUserID){
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email,user_birthday',
));
$this->abortToUrl($loginUrl);
}
try {
$user_profile = $facebook->api('/me');
if (!is_array($user_profile) || empty($user_profile['email'])) {
if ($log = $this->getLog()) {
$log->log('Facebook login no valid userprofile', Zend_Log::ALERT, array('user_profile' => $user_profile));
}
$this->abortToUrl($landingPage_url);
}
// 2.a User has provided data go on...
} catch (FacebookApiException $e) {
// 2.b Something bad happened. Worst case scenario so go to start
if ($log = $this->getLog()) {
$log->log($e->getMessage(), Zend_Log::CRIT);
}
// If he declined or anything went wrong go to LP
$this->abortToUrl($landingPage_url);
}
So I get quite a few logs with the user array not containing the email address field.
Am I missing something? I cannot reproduce this with test accounts or my account when I set email to be visible only to me.
Not every user has an email address set with FB, since you can also register using your mobile.