Reputation: 5959
I've recently started working on manual login flow of facebook. And followed this blog to get the access token and using restfb to access user information.
Below is the code snippet as mentioned - Fetching Single Objects:
FacebookClient facebookClient = new DefaultFacebookClient(ACCESS_TOKEN, APP_SECRET);
User user = facebookClient.fetchObject("me", User.class);
I'm successfully able to get the user's name, first name and last name but it returns null
for email
(user.getEmail();
).
My facebook app has default permissions as:
Anyone help me how can I access the user email?
UPDATE
I've been trying the graph-api
explorer to see what I'm getting for email
and it says
Field is empty or disallowed by the access token
. What do I'm supposed to do to fix this?
Upvotes: 2
Views: 2836
Reputation: 91
Try this
User me = client.fetchObject(yourId, User.class,Parameter.with("fields", "email"));
Upvotes: 9
Reputation: 19995
Either the user doesn't have his email listed or you aren't requesting the email
permission in scope.
Check that you have email
permissions with a request to me/permissions
In that blog post mentioned the email
should be set in the getLoginRedirectURL
. To ensure this when you go through a login dialog check that the Facebook login dialog asks for email permission.
This is also described in the manual flow
https://www.facebook.com/dialog/oauth?
client_id={app-id}
&redirect_uri={redirect-uri}&scope=email
Upvotes: 0