According to Facebook's official documentation, email access is given to any app provided user accepts and grants permission when login using Facebook.
I've double checked our app definition and I can see email should be accessible.
I'm using the latest available from Spring Social
<spring-social-security>1.1.4.RELEASE</spring-social-security>
<spring-social-core>1.1.4.RELEASE</spring-social-core>
<spring-social-facebook>2.0.3.RELEASE</spring-social-facebook>
Users successfully login using Facebook as a provider as well as Google+ and Twitter.
Unfortunately for all cases email is NULL except for my own user.
There are two scenarios where email could be null though
I've triple checked that by accessing a friend's of mine account which
I go to the GraphApi explorer but no email is ever returned.
Any advice? Thank you.
I found where the problem was. I was not adding the required scopes to the social connection factory.
FacebookConnectionFactory fcf = new FacebookConnectionFactory(
env.getProperty("oauth.facebook.api.key"),
env.getProperty("oauth.facebook.api.secret"));
//this is the important bit
fcf.setScope("public_profile,email");
.....
email was missing.
Maybe the problem is that you tries to fetch username. Currently, Facebook got rid of the username because the username is one way of sending emails via Facebook.
You can try to delete this line:
final String uemail = userProfile.getUsername();
and check if you can get email. Here is my code that I use to fetch email etc.:
OAuth2Operations oauthOperations = fbProvider.getOAuthOperations();
AccessGrant accessGrant = oauthOperations.exchangeForAccess(authorizationCode, facebookCallback, null);
String accessToken = accessGrant.getAccessToken();
Connection<Facebook> connection = fbConnectionFactory.createConnection(accessGrant);
UserProfile profile = connection.fetchUserProfile();
ConnectionKey connectionKey = connection.getKey();
String usn = connectionKey.getProviderUserId();
String email = profile.getEmail();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With