angular-facebook icon indicating copy to clipboard operation
angular-facebook copied to clipboard

Cannot get user email address

Open asankaub opened this issue 10 years ago • 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'});
    };

asankaub avatar Nov 17 '15 17:11 asankaub

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

kim0z avatar Jan 30 '16 14:01 kim0z

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);

                });

            });
        };

kim0z avatar Jan 30 '16 17:01 kim0z

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

sherizan avatar Feb 01 '16 13:02 sherizan

Thanks, looks more arranged than my code, Cool.

kim0z avatar Feb 02 '16 11:02 kim0z

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

nfedosenko-old avatar Feb 02 '16 14:02 nfedosenko-old

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

kim0z avatar Feb 03 '16 09:02 kim0z

@sherizan, I'm getting:

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

Any idea?

rochapablo avatar Apr 19 '16 13:04 rochapablo

Never mind! I've just changed to:

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

rochapablo avatar Apr 19 '16 13:04 rochapablo

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?

melody1798 avatar May 20 '16 14:05 melody1798

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.

rochapablo avatar May 20 '16 14:05 rochapablo

@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.

LGRI avatar Jun 07 '16 10:06 LGRI

This return email

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

boogie1989 avatar Aug 09 '16 13:08 boogie1989

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 avatar Aug 30 '16 13:08 nitin-healthians

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

chawlaaditya8 avatar May 06 '17 11:05 chawlaaditya8

@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;
		}
	},

nitin-healthians avatar May 08 '17 06:05 nitin-healthians