用js实现facebook登录获取用户的信息(包括邮箱)

//要挂代理

<html><body>

<div id="fb-root"></div>
<script>
  // Additional JS functions here

  window.fbAsyncInit = function() {

var facebookId;
var facebookName;
var facebookEmail;
    FB.init({
      appId      : 你网站上的id, // App ID
      channelUrl : '用facebook登录后返回页面的URL', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });


  FB.Event.subscribe('auth.authResponseChange', function(response) {

    if (response.status === 'connected') {

//测试返回出来的值

      testAPI();
    } else if (response.status === 'not_authorized') {
      FB.login();
    } else {
      FB.login();
    }
  });

  };


  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);

   }(document)); 


  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
//for(var i in response)
//{
//console.log(i+":"+response[i]);
//}
      retrieveProfiles(response['id']);
    });
  }

function retrieveProfiles(id) {
    // 通过Facebook API 查询用户信息
    FB.api({ method: 'fql.query', query: "SELECT uid,email, name, pic_square, books, movies, music, current_location FROM user WHERE uid="+id}, function(response) {
for(var i in response)

{

//显示用户的信息

for(var j in response[i])
console.log(j+":"+response[i][j]);
}
    });
}
</script>

<body>

//红色表示获得网站访问用户邮箱的权限

<fb:login-button show-faces="true" width="200" max-rows="1" scope="email,user_checkins"></fb:login-button>
</body></html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值