doulan7166 2013-07-24 08:32
浏览 589

我无法在Facebook上获得用户电子邮件地址

i have a big problem with this code. I try to write my first facebook app. But this code cant get email from user, and i dont know why. Can someone help me?

require_once 'phpmailer.php';
require_once 'facebook.php';

error_reporting(0);
//Application Configurations
$app_id     = 'MY APP ID';
$app_secret = 'MY SECRET ID';
$site_url   = 'MY SITE URL';
// Create our application instance
$facebook = new Facebook(array(
    'appId'     => $app_id,
    'secret'    => $app_secret,
    'cookie'=>true,
));

$user = $facebook->getUser();

if($user == 0){
    $user = $facebook->getUser();
}
if($user){
    $user_profile=$facebook->api('/me');    
    $logoutUrl= $facebook->getLogoutUrl();
    if(empty($_POST['send'])){
        echo"<form method='POST'>";
        echo"Hi ".$user_profile['name']."</br>";

        echo"<textarea name='message' rows='6' cols='80'>";
        echo"</textarea>";
        echo"<input type='submit' name='send' value='send'>";
        echo"</form>";
    }
    if(!empty($_POST['send'])&& empty($_POST['message'])){
        echo "Empty message";
    }
    if(!empty($_POST['send'])){
        $mail = new PHPMailer();
        $mail->SetFrom($_POST['mail'],$user_profile['name']);
        $mail->CharSet="utf-8";
        $address="therimsilua@gmail.com";
        $mail->AddAddress($address," ");
        $mail->Subject="message from facebook";
        $wiadomosc='Message from user'.$user_profile['name'].'</br>'.$_POST['message'];
        $mail->MsgHTML($message); 
        if($mail->Send()){
            echo "Send to: ".$user_profile['email']; 
        }
        else{           
            echo "Error:".$mail->ErrorInfo;
        }
    }               
}
else {
    $perm = array('scope'=>'email');
    $loginUrl =$facebook->getLoginUrl($perm);       
}

in App setting i have User & Friend Permissions email , so where is the error ? This app work fine without scope

require_once "facebook.php";

$facebook = new Facebook(array('appId'  => '482455065177441', 'secret' => '0e484981225df74f1170c29185aa8690'));  

$user_fb = $facebook->getUser();

if($user_fb == 0)
{
    $user_fb = $facebook->getUser();
}

if ($user_fb) // Check user's FB user ID has getting or not
{   
$user_profile = $facebook->api('/me'); 

$logoutUrl = $facebook->getLogoutUrl(); 

echo $user_profile['email'];
echo $user_profile['first_name'];
echo $user_profile['last_name'];            
}

else // user's FB user ID has not getting load login url with email permission
{     
 $perms = array('scope' => 'email');
 $loginUrl = $facebook->getLoginUrl($perms);        
 echo "<script> top.location.href='" . $loginUrl . "'</script>";        
}
  • 写回答

2条回答 默认 最新

  • dtzd65908 2013-07-31 09:07
    关注

    You are doing it right, but the email will only be displayed for the users who have set their privacy options for their emails to be shown to all, otherwise it wont display you the email of the user.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决