facebook登录按钮获取邮箱的方式

admin5年前IT技术1480

由于公司英语商城要做免注册登录,我就想到了facebook,按照官方的文档,一步一步做下去,心情很好,竟然没有坑,但是我高兴的太早了,上线测试了一下发现无法获取用户的邮箱与头像,那有什么用呢.

然后就是查官方,文化差异,那文档就不是写给你中国人看的,最后经过2个多小时的的折腾,终于搞出来了,直接上代码

  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

  // Here we run a very simple test of the Graph API after login is
  // successful.  See statusChangeCallback() for when this call is made.
  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me?fields=name,picture,email', function(response) {
      console.log(response);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' +response.name+"<br>"+response.email+"<br>"+'<img src="'+ response.picture.data.url + '">';
    });
  }

 

关键是FB.api('/me?fields=name,picture,email', function(response) {

官方竟然没有给出这个M文档!!!!!

官方文档https://developers.facebook.com/docs/facebook-login/permissions/#reference-default

授予您的应用访问User对象的默认字段的权限,这些字段是人员公开个人资料的子集:

  • id
  • first_name
  • last_name
  • middle_name
  • name
  • name_format
  • picture
  • short_name

 

相关文章

mount:is write-protected, mounting read-only解决方案

window10升级之后就遇到mount: **** is write-protected, mounting read-onlymount: cannot mount *** read-only尝试...

云图框架

 https://themes.getbootstrap.com/云图框架 ...

通过IP获取MAC地址

关键知识点:ARP缓存时间是十分钟;实现的命令是:第一步  ping  ip第二部  arp -a基础解释:在底层的网络通信中,两个节点想要相互通信,必须先要知道源与目标...

汇成机械行业企业网站系统v11.1

汇成机械行业企业网站系统v11.1˂a target="_blank" href="download/jixie/jixiehangye11.rar"˃官方下载汇成企业网站管理系统为中小企业免费建立属...

Android Studio下载sdk失败的解决方案

在浏览器打开这个网站http://ping.chinaz.com/dl.google.com或者:https://www.ping.cn/ping/dl.google.com他会列出一个ip列表,挨个...

sql语句 REPLACE 区分大小写字母的

 REPLACE  sql语句 REPLACE 区分大小写字母的;要注意...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。