0

我为我的网站添加了 facebook 登录按钮。代码如下,

<html>
<head>
<title>My Great Web page</title>
</head>
<body>

<div id="fb-root"></div>
<script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'MY_APP_ID',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
          });

        };

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

<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1" scope="user_about_me,user_activities,user_birthday,email"  on-login="top.location = 'http://localhost/index.php/';">Login with Facebook</div>

</body>
</html>

当用户单击“使用 facebook 登录”按钮时,将显示具有扩展权限的身份验证窗口。当用户允许访问详细信息时,用户将被定向到 index.php 文件使用

on-login="top.location = 'http://localhost/index.php/';"

现在我想打印所有允许访问的详细信息,例如用户名、生日等。在 index.php 文件中
谁能告诉我该怎么做?

4

1 回答 1

1

我不知道你在哪里得到这个登录按钮的登录属性(我找不到它),但这里有一个例子,你可以做你想做的事。它没有经过测试,我只是为了让你明白这一点而创建了这个。

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId: 'MY_APP_ID',
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true,
        });
    };

     FB.Event.subscribe("auth.login", function (response) {
        if (response.status == "connected") {
            var userid = response.authResponse.userID;
            var signedRequest = response.authResponse.signedRequest;
            var expiresIn = response.authResponse.expiresIn;
            var accessToken = response.authResponse.accessToken;

            // do something with the data.

            window.location = "index.php";
        }
     });

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

<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1" scope="user_about_me,user_activities,user_birthday,email">Login with Facebook</div>

您可以在此处阅读有关订阅事件的更多信息:FB.Event.subscribe,并且您可能会发现此线程很有用:Get user basic information using facebook Login button plugin?

于 2012-03-20T08:22:39.217 回答