Reputation: 1
I have a problem with obtaining of email from Facebook. After logging me sends all data such as name, last name, etc. but I miss email they need.
GraphObject{graphObjectClass=GraphUser, state={"id":"1069060169776842","first_name":"Peter","timezone":1,"verified":true,"name":"Peter Javorek","locale":"sk_SK","link":"https:\/\/www.facebook.com\/app_scoped_user_id\/1069060169776842\/","last_name":"Javorek","gender":"male","updated_time":"2014-12-18T12:28:15+0000"}}
On the Facebook developer I created a new project where I joined Key Hashes and I took thence App ID and add it to the application as tutorial.
I enabled the application to the public, and contain LOGIN PERMISSIONS:
- email
- public_profile
- user_friends
I used - Facebook SDK 3.23.0
This is my code:
private UiLifecycleHelper uiHelperFB;
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.v("motozo", "SessionOpen: ***");
for (String sessionData : session.getPermissions()) {
Log.v("", "PERMISSIONS: " + sessionData);
}
GraphUserCallback graphUserCallback = new GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
Log.v("", "Return: " + String.valueOf(user));
}
};
Request request = Request.newMeRequest(session, graphUserCallback);
request.executeAsync();
} else if (state.isClosed()) {
Log.v("", "Logged out...");
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelperFB.onSaveInstanceState(outState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_first_page);
super.onCreate(savedInstanceState);
uiHelperFB = new UiLifecycleHelper(this, callback);
uiHelperFB.onCreate(savedInstanceState);
LoginButton fbLoginButton = (LoginButton) findViewById(R.id.fb_login_button);
fbLoginButton.setPublishPermissions(Arrays.asList("email"));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelperFB.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onStop() {
super.onStop();
uiHelperFB.onStop();
}
@Override
protected void onResume() {
super.onResume();
uiHelperFB.onResume();
}
@Override
protected void onPause() {
super.onPause();
uiHelperFB.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelperFB.onDestroy();
}
These are listings:
02-13 15:19:58.878 14054-14054/facebookLog V/﹕ SessionOpen: ***
02-13 15:19:58.878 14054-14054/facebookLog V/﹕ PERMISSIONS: email
02-13 15:19:58.878 14054-14054/facebookLog V/﹕ PERMISSIONS: publish_actions
02-13 15:19:58.878 14054-14054/facebookLog V/﹕ PERMISSIONS: basic_info
02-13 15:19:59.154 14054-14054/facebookLog V/﹕ Return: GraphObject{graphObjectClass=GraphUser, state={"id":"1069060169776842","first_name":"Peter","timezone":7,"verified":true,"name":"Peter Javorek","locale":"sk_SK","link":"https:\/\/www.facebook.com\/app_scoped_user_id\/1069060169776842\/","last_name":"Javorek","gender":"male","updated_time":"2014-12-18T12:28:15+0000"}}
Thanks for help.
EDIT:
After further testing with other FB accounts we have noticed that FB does send the email in the me request, but it does so only for some accounts, for other accounts it doesn't send email even when they have email in their profile. Are there some settings which affect this? Anyway to deal with this so that we get that email also for those accounts which don't send it to us normally?
Upvotes: 0
Views: 241
Reputation: 1137
You have to do a special graph call for email, it's not in the default response, see the snippet here:
https://stackoverflow.com/a/28439577/1134723
Upvotes: 0