如何使用javascript sdk获取Facebook用户的电子邮件ID [英] how to get email id of Facebook user using javascript sdk

查看:145
本文介绍了如何使用javascript sdk获取Facebook用户的电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaScript API为Facebook创建我的应用程序。问题是,它正在返回

email = undefined

I am using JavaScript API to create my app for Facebook. The problem is, it's returning
email = undefined.

我不知道为什么?如果我在我的应用程序中使用Facebook登录/注销按钮,那么该警报会显示用户的正确电子邮件ID,但我不想这样做。
我错过了什么?

I don't know why? And if I use Facebook login/logout button on my app then the alert shows correct email id of the user but I don't want to do that. What am I missing?

这是我的代码:

<p><fb:login-button autologoutlink="true" perms="user_about_me,email"></fb:login-button></p>

<script>
window.fbAsyncInit = function () {
  FB.init({ appId: '250180631699888', status: true, cookie: true,
  xfbml: true
});

  FB.getLoginStatus(function (response) {
    if (response.session) {
      greet();
    }
  });
};
(function () {
  var e = document.createElement('script');
  e.type = 'text/javascript';
  e.src = document.location.protocol +
  '//connect.facebook.net/en_US/all.js';
  e.async = true;
  document.getElementById('fb-root').appendChild(e);
} ());

function greet() {
  FB.api('/me', function (response) {
  alert('Welcome, ' + response.name + "!");
  alert('Your email id is : '+ response.email);
});
}
</script>


推荐答案

根据Facebook页面上的最新信息,使用范围而不是烫发。
https://developers.facebook.com/docs/reference/javascript/FB.login /

According to the latest info on the facebook page you should use 'scope' instead of perms. https://developers.facebook.com/docs/reference/javascript/FB.login/

如果您访问

https://developers.facebook.com/tools/console/

并使用fb-api - >用户信息示例作为起点,然后注销并重新登录,它应该要求您发送电子邮件,您可以看到您的电子邮件正在打印。您在发布时提到的是使用response.email。

and use the fb-api -> user-info example as a starting point, then logout and back in again, it should ask you for email perms and you can see your email being printed. It is done using response.email as you mention in your post.

这篇关于如何使用javascript sdk获取Facebook用户的电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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