faysalmirmd

Facebook Login using Javascript SDK

Nov 4th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. $script = '<script type=\'text/javascript\'>
  2.                     window.fbAsyncInit = function() {                                                                                          
  3.                            FB.init({ appId: \''.$consumerKey.'\',
  4.                                    status: true,
  5.                                    cookie: true,
  6.                                    xfbml: true,
  7.                                    oauth: true
  8.                            });
  9.  
  10.                            button         = jQuery(\'#fb-auth\');
  11.                            ajaxloader     = jQuery(\'#cbajaxloader\');
  12.                            
  13.                            button.click(function(event) {
  14.                                event.preventDefault();
  15.                                
  16.                                    FB.login(function(response) {
  17.                                        if (response.authResponse) {
  18.                                            FB.api(\'/me\', function(info) {
  19.                                                login(response, info);
  20.                                            });
  21.                                        } else {
  22.                                            //user cancelled login or did not grant authorization
  23.                                        }
  24.                                    }, {scope:\'offline_access,manage_pages,read_stream,user_about_me\'});
  25.                            });
  26.                        };
  27.                        (function() {
  28.                            var e = document.createElement(\'script\'); e.async = true;
  29.                            e.src = document.location.protocol
  30.                                + \'//connect.facebook.net/en_US/all.js\';
  31.                            document.getElementById(\'fb-root\').appendChild(e);
  32.                        }());
  33.  
  34.                        function login(response, info){
  35.  
  36.                            if (response.authResponse) {
  37.                                    var accessToken   =   response.authResponse.accessToken;
  38.                                    
  39.                                    jQuery.ajax({
  40.                                        type        : \'POST\',
  41.                                        url         : \'index.php?option=com_cbsocialappsoauth&task=fbatstore&format=raw\',
  42.                                        data        : {     \'accesstoken\'          : accessToken,
  43.                                                            \'app\'                  : \'responsivefacebookpagestreammod\',
  44.                                                            \'consumerkey\'          : \''.$consumerKey.'\',
  45.                                                            \'consumersecret\'       : \''.$consumerSecret.'\',
  46.                                                            \'extid\'                : '.$extid.',
  47.                                                            \''.JSession::getFormToken().'\' : 1
  48.                                                        },
  49.                                        beforeSend  : function(){
  50.                                                        ajaxloader.css({ display:"block" });
  51.                                                    },
  52.                                        success     : function(data){
  53.                                                        window.location=\''.JRoute::_($callback).'\';
  54.                                                    },
  55.                                        error       : function(){
  56.                                                            // failed request; give feedback to user
  57.                                                    }
  58.                                    });
  59.                                                
  60.                            }
  61.  
  62.                        }
  63.  
  64.                        function logout(response){
  65.  
  66.                        }
  67.                        </script>';
Advertisement
Add Comment
Please, Sign In to add comment