Search code examples
facebookcordovasencha-touch-2inappbrowser

Inappbrowser callback


I have tried to call back after login in facebook using inappbrowser. But it doesnt work to check the email,name etc.Here my code

Inappbrowser calling

function onDeviceReady(){   
     var my_client_id = FBkey,
     my_redirect_uri = "http://www.fastabuy.com/index.php",
     my_type = "user_agent",
     my_display = "touch";

     var authorize_url = FBgraphapiurl+"/oauth/authorize?";
     authorize_url += "client_id=" + my_client_id;
     authorize_url += "&redirect_uri=" + my_redirect_uri;
     authorize_url += "&display=" + my_display;
     authorize_url += "&scope=publish_stream,email,user_likes";
     isfir = "true";

     var ref = window.open(authorize_url, '_blank', 'location=yes');
     ref.addEventListener('loadstop', function facebookLocChanged() {
         facebookLoc(my_redirect_uri)
     });
}

Method for checking call back

  function facebookLoc(loc){
     if (loc.indexOf("http://www.fastabuy.com/index.php?") > -1){
       alert(loc.indexOf)
     }
  }

How to check when the url loc.indexOf>-1 to close the inappbrowser. Please help me to sort this out.


Solution

  • 1) You need to use loadstart event in InAppBrowser for checking redirected page.

    2) After successful login use close method for closing InAppBrowser.

    3) When you call facebookLoc function in callback, you should watch out for scope and i am using me variable to solve this problem.

    onFacebookLogin: function() {
    
        var me = this;
        var appInBrowser = window.open(authorize_url, '_blank', 'location=yes');
    
        appInBrowser.addEventListener('loadstart', function(event) {
             me.facebookLoc(event.url,appInBrowser);
        });    
    }
    
    facebookLoc : function(loc,appInBrowser) {
       if (loc.indexOf("www.facebook.com/connect/login_success.html") > -1){
             alert('Login success');
             appInBrowser.close();
       }
    }