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

admin5年前IT技术1460

由于公司英语商城要做免注册登录,我就想到了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

 

相关文章

magento2.x系统加速

magento2.x系统加速

1:在根目录运行以下命令,全站生成静态bin/magento setup:static-content:deploy2:编译整个网站,让网站加速50%  注意事项:要把PHP脚本内存限制设置...

判断mysql字段是否为空

 字段内容为空有两种情况  1.为null  2.为字符串的空'' 字段 is null or trim(字段)=''...

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

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

社交营销的核心知识

1.拉新,裂变,自动传播2.价格战,社交形式?3.人:贪小便宜,精确匹配到客户的分类产品[根据大数据]|4.C2B的模式,提高单个SKU的订单量,降低单个相同SKU的生成成本,让用户享受到高品质的产品...

王石:宁登一座山,不谋一餐饭

王石:宁登一座山,不谋一餐饭

王石:宁登一座山,不谋一餐饭。听王石讲人情堆里这些年的故事,也曾喝酒喝到胃出血,也曾“行贿未遂”,但还是愿意打造简单、透明、规范的商业王国。登珠峰与吃顿饭,二者孰难孰易?相信一...

发表评论    

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