使用Facebook数据自动填写我的自定义表单 [英] Auto fill my custom form using facebook data

查看:264
本文介绍了使用Facebook数据自动填写我的自定义表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设计的表单接受输入值。我希望人们点击注册为Facebook按钮,其中包含他们的Facebook详细信息,因此填写了我的自定义表单和适当的值。我希望它像这样。 https://www.odesk.com/signup/create-account/id /Contractor_50dbed1edc1416.20352143



请告诉我如何才能实现?

解决方案

注册插件是您正在寻找的。 :)



更新



如果您想要自定义表单。您必须获得用户的许可并获得他的详细信息。您可以使用以下代码:

 < div id =fb-root>< / div> 
< script src =https://connect.facebook.net/en_US/all.js>< / script>
FB.init({appId:'XXXXXXXXXXXXX',status:true,xfbml:true,cookie:true,oauth:true});


函数login(){
FB.getLoginStatus(function(response){
//检查用户是否已经授权
if(response.status ==='connected'){
FB.api('me?fields = id,name,email',function(user){
if(user!= null){
username = user.name;
uid = user.id;
email = user.email;
}
});

} else {
//如果用户没有授权调用FB.login弹出窗口进行授权,范围定义用户
请求的持续性列表FB.login(function(response){
if(response.authResponse.accessToken){
FB.api('me?fields = id,name,email',function(user){
if(user!= null){
username = user.name;
uid = user.id;
email = user.email;
}
})
}
},{scope:'email'});
}

});
}

您按下按钮可以拨打login()。


I have a form designed which takes input values. I want people to click the button "sign up as facebook" which takes in their facebook details and as a result fills my custom form with the appropriate values. i want it to be like this one. https://www.odesk.com/signup/create-account/id/Contractor_50dbed1edc1416.20352143

Please tell me how can this be achieved?

解决方案

Registration Plugin is what you are looking for. :)

UPDATED

In Case you want to have custom form. You would have to take permission from user and get his details. You can use following Code :

<div id="fb-root"></div> 
<script src="https://connect.facebook.net/en_US/all.js"></script> 
FB.init({appId: 'XXXXXXXXXXXXX',status : true,xfbml  : true, cookie: true ,oauth  : true});


function login(){
        FB.getLoginStatus(function(response) {
        // checks if user already authorized
                    if (response.status === 'connected') {
                            FB.api('me?fields=id,name,email', function(user) {
                                     if(user != null) {
                                                                username  = user.name;
                                                                uid = user.id;
                                                                email = user.email;
                                                            }
                                });

                    } else {
        // If user is not authorized call FB.login for pop up window for authorization  , scope defines list of persmission requested with user
                    FB.login(function(response) {
                            if (response.authResponse.accessToken) {    
                                            FB.api('me?fields=id,name,email', function(user) {
                                                    if(user != null) {
                                                                username  = user.name;
                                                                uid = user.id;
                                                                email = user.email;
                                                            }
                                                        }) 
                                                    } 
                                                }, {scope:'email'});
                    }

                });
    }

You call login() at the press of your button.

这篇关于使用Facebook数据自动填写我的自定义表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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