How to get email id in facebook login ngcordova callback object

I installed the corova inapp browser plugin to add facebook social login. The fact is that in my application I allowed login only through facebook and did not subscribe. On my website, if this user is registered, only he can access the mobile application. So, to make a signin from a mobile application, after the callback, you can get the email identifier that the user provided in the inapp browser, which opens when you click on the facebook button? If I get an email id, can I cross-check his / her existence in the database? Is it possible to do this?

My code is:

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

In the above example email, the argument contains the user data that I want to get from facebook on successful login. But I get access_tokenthat is about 50 digits and another parameter expires_inwith a time stamp of 7 digits. I do not receive email here. How to get it?

+4
source share
1 answer

$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);
        });
}
Run codeHide result

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

+5
source

All Articles