luiscarlosjayk/angular-facebook

Cannot get user email address

asankaub opened this issue · 15 comments

I added following function to get email address, but its not returning the email address.
its returning only,
accessToken: ""
expiresIn: 5874
signedRequest: ""
userID: ""

Function

$scope.login = function () {
        Facebook.login(function (response) {
            if (response.status == 'connected') {
                $scope.logged = true;
                $scope.me();
            }

        },{scope: 'email'});
    };
kim0z commented

The same for me, any idea what we are missing?

kim0z commented

I found the issue, we should extract the information like this:

   $scope.me = function () {
            Facebook.api('/me?fields=email', function (response) {
                /**
                 * Using $scope.$apply since this happens outside angular framework.
                 */
                $scope.$apply(function () {
                    $scope.user = response;

                    console.log($scope.user);

                });

            });
        };
$scope.me = function() {
      Facebook.api('/me', {fields: 'email,name'}, function(response) {
        $scope.user = response;
        // Examples
        $scope.welcome = response.name;
        $scope.userEmail = response.email;
      });
};
kim0z commented

Thanks, looks more arranged than my code, Cool.

Is there any way to get ALL of the fields without defining them in the fields property?

kim0z commented

No, you should ask for the exact permission, and if you want more than public profile then Facebook will review your request: https://developers.facebook.com/docs/facebook-login/permissions#checking

@sherizan, I'm getting:

(#100) Tried accessing nonexisting field (public_profile) on node type (User)

Any idea?

Never mind! I've just changed to:

/me?fields=name,email,age_range,gender,locale

I tried /me?fields=name,email,age_range,gender,locale.
But still couldn't get email address.
I am wondering that login window is not asking permission confirmation.
What is the problem?

I'm not sure yet, because I still working on development env. But I think that even setting these fields, you must set them at your FB dev dashboard. So that way the FB will allow you get those fields.

LGRI commented

@melody1798 Facebook will check email validity of every user, if they found the email is not in use, user email will not be return from graph api call.

This return email

Facebook.login(function(response) {
Facebook.api('/me?fields=name,email', function(user) {
//do something with user
});
}, { scope: 'email' });

I am getting email when i am login with that email id of app created account but if i am login with other email account then user email will not be return from graph api call.

@nitin-healthians i am getting the same error, did you solve it?

@chawlaaditya8

getFBLoginStatus : function() {
Facebook.getLoginStatus(function(response) {
if (response.status == 'connected') {
userIsConnected = true;
}
else if (response.status === 'not_authorized') {
userIsConnected = false;
}
else {
userIsConnected = false;
}
});
return userIsConnected;
},
fbloginme : function() {
var deferred = $q.defer();
Facebook.login(function(response) {
Facebook.api('/me', { fields: 'email,name,gender' }, function(response) {
var opts = {
name: response.name,
email: response.email,
termscond: "1",
social_login: "Facebook",
social_response: response,
gender: response.gender
};
deferred.resolve(opts);
});
}, {scope: 'email'});
return deferred.promise;
},
fbme :function() {
var deferred = $q.defer();
Facebook.api('/me', { fields: 'email,name,gender' }, function(response) {
var opts = {
name: response.name,
email: response.email,
termscond: "1",
social_login: "Facebook",
social_response: response,
gender: response.gender
};

            deferred.resolve(opts);
        });	
        return deferred.promise;
    },
	**fblogin** : function (callback) {
		var deferred = $q.defer();
		var userIsConnected = this.getFBLoginStatus();
		if(!userIsConnected) {
			var promise = this.fbloginme();
			return promise;
		}
		else {
	    	var promise = this.fbme();
	    	return promise;
		}
	},