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

admin6年前IT技术2191

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

 

相关文章

centos 秘钥登陆配置

centos 秘钥登陆配置

 准备:2台机器,ip分别为:10.1.80.13     10.1.80.14目的:通过13 ssh远程访问14.无需输入密码1、首先在10.1.80.13上...

magento2.x系统加速

magento2.x系统加速

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

L2TP端口

1701,1702,4500,500...

错误0xC004F069非核心版本的计算机上运行slui.exe解决方法

错误0xC004F069非核心版本的计算机上运行slui.exe解决方法

Windows 10系统使用slmgr命令添加密钥时出现错误:“0xC004F069在运行Microsoft Windows非核心版本的计算机上,运行 slui.exe 0x2a 0xC00...

GA设置排除中国的访问ip流量

GA设置排除中国的访问ip流量

1.视图过滤2.细分受众过滤...

asp移动APP单页应用开发前端后端框架v1.0

asp移动APP单页应用开发前端后端框架v1.0简称aspwn  1.0在线演示 ˂a href="download/aspwn.zip" target="_blank"˃官方下载开发此套框...

发表评论    

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