Auto fill my custom form using facebook data [closed]

六眼飞鱼酱① 提交于 2019-12-12 09:21:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14050528/auto-fill-my-custom-form-using-facebook-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!