使用Facebook登录按钮插件获取用户基本信息? [英] Get user basic information using facebook Login button plugin?

查看:184
本文介绍了使用Facebook登录按钮插件获取用户基本信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我使用 Facebook登录按钮插件 javascript sdk



我可以成功登录



当第一次使用用户进行身份验证过程时,我需要将用户基本信息(即Facebook登录名,电子邮件)存储在我的数据库中。 >

请建议我可以这样做。

 < p>< fb:login-button autologoutlink =true>< / fb:login-button>< / p> 


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


(function(){
var e = document.createElement('script');
e.type ='text / javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById(' fb-root')。appendChild(e);
}());
< / script>


解决方案

订阅活动 auth.login 。如果这样做,Facebook会在登录之后调用您的处理程序。



在该处理程序中,使用 FB.api 调用Graph API来获取所需的任何信息。例如,如第二个示例所示,调用 / me 将会获得有关登录用户的基本信息。



现在你有了所有的JavaScript数据。要发送到您的服务器,请执行一个简单的旧的XMLHttpRequest / AJAX请求。您的JavaScript库可能使这很容易 - 在jQuery中,这是 jQuery.ajax() - 但最糟糕的情况是您可以直接使用XHR



现在,您有服务器上的数据,您可以执行任何所需的操作,例如将其存储在数据库中。如果您只想存储一次数据,只需检查您尚未存储该用户ID的信息。


Here I am using Facebook Login button plugin and javascript sdk

I am able to successfully login and logout by using above.

When a first time user has gone through authentication process I need to store user basic information i.e. Facebook login name, email in my database.

Please suggest how I can do this.

<p><fb:login-button autologoutlink="true"></fb:login-button></p>


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


        (function () {
            var e = document.createElement('script');
            e.type = 'text/javascript';
            e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        } ());
    </script>

解决方案

Subscribe to the event auth.login. If you do this, Facebook will call your handler after a login as happened.

In that handler, use FB.api to call the Graph API to get any information you desire. For example calling /me as shown in the second example will get you basic information about the logged in user.

Now you have all the data in JavaScript. To send that up to your server, do a plain old XMLHttpRequest/AJAX request. Your JavaScript library probably makes this easy -- in jQuery this is jQuery.ajax() -- but worst case you can use XHR directly.

Now you have the data on your server and you can do whatever you want, like store it in the database. If you only want to store the data once, just check that you haven't already stored info about that user ID yet.

这篇关于使用Facebook登录按钮插件获取用户基本信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆