我不能在Facebook上收到用户电子邮件地址 [英] I cant get user email address on facebook
问题描述
require_once'phpmailer.php';
require_once'facebook.php';
error_reporting(0);
//应用程序配置
$ app_id ='我的APP ID';
$ app_secret ='我的秘密ID';
$ site_url ='我的网站网址';
//创建我们的应用程序实例
$ 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'>;
echoHi$ 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'])&&(($ _ POST ['message'])){
echoEmpty 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 =来自Facebook的消息;
$ wiadomosc ='来自用户的消息'$ user_profile ['name']。'< / br>'。$ _ POST ['message'];
$ mail-> MsgHTML($ message);
if($ mail-> Send()){
echoSend to:$ user_profile ['email'];
}
else {
echo错误:$ mail-> ErrorInfo;
}
}
}
else {
$ perm = array('scope'=>'email');
$ loginUrl = $ facebook-> getLoginUrl($ perm);
}
在应用设置中,我有用户&朋友权限电子邮件,所以错误在哪里?
这个应用程序工作正常没有范围
require_oncefacebook.php;
$ facebook = new Facebook(array('appId'=>'482455065177441','secret'=>'0e484981225df74f1170c29185aa8690'));
$ user_fb = $ facebook-> getUser();
if($ user_fb == 0)
{
$ user_fb = $ facebook-> getUser();
}
if($ user_fb)//检查用户的FB用户ID是否有
{
$ user_profile = $ facebook-> api('/我');
$ logoutUrl = $ facebook-> getLogoutUrl();
echo $ user_profile ['email'];
echo $ user_profile ['first_name'];
echo $ user_profile ['last_name'];
}
else //用户的FB用户ID没有获取加载登录URL,具有电子邮件权限
{
$ perms = array('scope'=>'电子邮件');
$ loginUrl = $ facebook-> getLoginUrl($ perms);
echo< script> top.location.href ='。 $ loginUrl。 < /脚本>中;
}
Facebook不会返回用户当且仅当用户在身份验证期间拒绝访问时才发送电子邮件。尝试打印 print_r($ user_profile)
请求facebook api返回。或者您可以使用 opauth php身份验证库,并且易于使用希望它有助于
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>";
}
Facebook would not return the user's email if and only if the user denies u access during authentication. Try to print print_r($user_profile)
out the request facebook api returns. or you can use opauth a php authentication library sleeky and easy to use hope it helps
这篇关于我不能在Facebook上收到用户电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!