使用fb图表登录画布应用程序时如何获取电子邮件? [英] How to get e-mail when logging into canvas application using fb graph?

查看:199
本文介绍了使用fb图表登录画布应用程序时如何获取电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户登录到我的Facebook画布应用程序时只使用fb图形API获取用户电子邮件?我不想使用Facebook php sdk,因为我无法使用此代码处理它(实际上,我尝试了很多但是失败)Plz帮助

I want to get the user email when the user logged into my facebook canvas application using only fb graph api?I dont want to use facebook php sdk as I can not handle it with this code(Actually,I tried a lot but failed)Plz help

$app_id = "xxxxxxx";

$canvas_page = "xxxxxxxx";

$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page);

$signed_request = $_REQUEST["signed_request"];

list($encoded_sig, $payload) = explode('.', $signed_request, 2);

$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), TRUE);

if(empty($data["user_id"])) 
{
    echo("<script> top.location.href='" . $auth_url . "'</script>");
} 
else 
{
    echo ("Welcome User: " . $data["user_id"]);
    echo ("Welcome User: " . $data["email"]);   //i tried this
}


推荐答案

电子邮件字段可以在FB API的用户对象中找到,但只有在您明确要求电子邮件权限。有许多方法可以请求此权限,例如

The 'email' field can be found within the FB API's user object, but only if you have explicitly asked for email permissions. There are many ways to request this permission, e.g.

$param['scope'] = "email";
$login_url = $facebook->getLoginUrl($param);
echo 'Please <a href="' . $login_url . '">login.</a>';

将打印一个授权电子邮件权限的登录网址。然后,您可以通过用户对象检索电子邮件,如以下示例所示:

will print a login url that authorizes email permissions. You can then retrieve an email through the user object, as in the following example:

$user_profile = $facebook->api('/me','GET');
echo "email: ".$user_profile['email'];

注意:应用程序无法获取用户的朋友的电子邮件地址。

Note: There is no way for apps to obtain email addresses for a user's friends.

这篇关于使用fb图表登录画布应用程序时如何获取电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆