How to get the email id in the ngcordova facebook login callback object

1.2k views Asked by At

I have installed the cordova inapp browser plugin to add the social facebook login. Thing is, in my app i have allowed only sign in through facebook and not sign up. On my webapp if that user has been registered then only he/she can access the mobile app. So to do the signin from mobile app, after callback is it possible to receive the email id which user provided in the inapp browser that opens on facebook button click? If i reveive email id the i can cross verify his/her existence in database? Is it possible to do that?

My code is this:

    $scope.getDeviceInfo = function() {
        $cordovaOauth.facebook("777846192309223", ["email"]).then(function(result) {
            alert('success login:'+JSON.stringify(result));
        }, function(error) {
            alert('error: '+error);
        });
}

In the above the email in the argument is the user data i want to get from facebook on successful login. But i am getting access_token that is somewhat around 50 digit and another one parameter expires_in with timestamp of 7 digits. I am not getting email here. How to get that?

1

There are 1 answers

0
cfprabhu On

$scope.getDeviceInfo = function() {
        $cordovaOauth.facebook("777846192309223", ["email"]).then(function(result) {
            alert('success login:'+JSON.stringify(result));
            $localStorage.accessToken = result.access_token;
            if($localStorage.hasOwnProperty("accessToken") === true) {
             $http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id,name,gender,location,website,picture,relationship_status",email format: "json" }}).then(function(result) {
                 $scope.profileData = result.data;
             }, function(error) {
                 alert("There was a problem getting your profile.  Check the logs for details.");
                 console.log(error);
             });
         } else {
             alert("Not signed in");
             $location.path("/login");
         }
        }, function(error) {
            alert('error: '+error);
        });
}

Store the access token to localstorage. And using facebook graph api to get user email id and etc