Reputation: 41
Hi there i am currently working on Facebook login for my website.
For now i can display everything else like First name, Second name, ID of facebook member id but i can't not display the email.
Here is my php code:
<?php
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'MYIDDDDDD',
'secret' => 'MYIDDDDDD',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
}
$naitik = $facebook->api('/naitik');
$myid = $user_profile['id'];
$myemail = $user_profile['email'];
echo $user_profile['first_name'];
echo "Your id is - $myid<br>My email is = $myemail";
$_SESSION['first_name']=$user_profile['first_name'];
?>
If it's important my App is in Sandbox mode.
Where is my mistake in this code and why $myemail = $user_profile['email'];
is show as blank?
Thanks in advance!
Upvotes: 0
Views: 152
Reputation: 724
Did you first get the users permission to see his email?
https://developers.facebook.com/docs/reference/login/email-permissions/
if not, see this post Set permission for getting User's email ID from Facebook Login
Upvotes: 1