简体   繁体   English

如何从Facebook收到电子邮件

[英]How to get email from facebook

I have created an application. 我创建了一个应用程序。 There is form, in which there are two fields email and name. 有表格,其中有两个字段的电子邮件和名称。 There is button, which enable you to login with facebook and after that it will get the user name and email. 有按钮,您可以使用Facebook登录,然后它将获得用户名和电子邮件。

I have tried many ways. 我尝试了很多方法。 I can get name and other detail, but I couldn't get user email. 我可以获得姓名和其他详细信息,但我无法收到用户电子邮件。 I have also used fql to get the email but didn't get. 我也使用fql来获取电子邮件,但没有得到。 Below is the code. 下面是代码。 I want to retrive that by PHP. 我想通过PHP来检索它。

$fql = 'SELECT contact_email FROM user WHERE uid = '.$user;
$res = $facebook->api(array('method' => 'fql.query',
                            'query' => $fql));

Can any one will tell me how to get the email. 任何人都可以告诉我如何收到电子邮件。 Any help will be appreciable. 任何帮助都会很明显。

use facebook->getLoginUrl with Email Permissions, see https://developers.facebook.com/docs/reference/login/email-permissions/ ( scope' => 'email' ) 使用facebook->getLoginUrl和电子邮件权限,请参阅https://developers.facebook.com/docs/reference/login/email-permissions/ ( scope' => 'email'

facebook.php : facebook.php

<?
error_reporting(E_ALL);
ini_set('display_errors','on');
require 'facebook-php-sdk-master/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => <YOUR AppId>,
  'secret' => <YOUR APPsecret>,
));

$applicationurl = 'http://testdrive.nl/facebook.php';

// Get User ID
$user = $facebook->getUser();

if(empty($user))
{
    $params = array(
  'scope' => 'email',
  'redirect_uri' => $applicationurl
   );   

$loginUrl = $facebook->getLoginUrl($params);
header('Location: ' . $loginUrl ."\r\n");
exit;
}   

$fql = 'SELECT contact_email FROM user WHERE uid = '.$user;
$res = $facebook->api(array('method' => 'fql.query',
                            'query' => $fql));
//var_dump($res);
echo $res[0]['contact_email'];

You'll need to require an additional permission from your users in order to get their email address. 您需要获得用户的额外许可才能获取其电子邮件地址。 This permission is aptly named email . 此权限恰当地命名为email

Depending on your method of authentication and user login, you'll have to add this email permission to your scope parameter. 根据您的身份验证方法和用户登录,您必须将此email权限添加到您的scope参数。 This scope parameter is where you add additional permissions to request from your user. scope参数是您向用户请求其他权限的位置。 You can ask for these permissions as the user installs your application but you can also request permission after the user has installed your application. 您可以在用户安装应用程序时请求这些权限,但您也可以在用户安装应用程序后请求权限。

For more info on the email permission, check out this link to the relevant documentation. 有关电子邮件权限的更多信息,请查看相关文档的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM