0

I've got this code (which was working in 11/2014) called from a button click:

Session.openActiveSession(this, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Request.newMeRequest(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(final GraphUser user, final Response response) {
                        if (user != null) {
                            System.out.println(user);
                            preference.edit().putString("fb_nome",user.getName()).commit();
                            preference.edit().putString("fb_id",user.getId()).commit();
                            preference.edit().putString("fb_email",user.asMap().get("email")+"").commit();
                            if(user.getLocation()!=null) {
                                preference.edit().putString("fb_citta", user.getLocation().asMap().get("name") + "").commit();
                            }
                            Session session = Session.getActiveSession();
                            preference.edit().putString("fb_token",session.getAccessToken()).commit();
                            new loginFacebook().execute();
                        }
                    }
                }).executeAsync();

            }
        }
    });

latest sdk and so on.

the problem is that facebook doesn't give me the email and the city anymore!

i'm sure it was working on 11/2014, but now no.

email is null and also the city...

someone can help me? thanks

D Ferra
  • 1,223
  • 3
  • 12
  • 21

2 Answers2

0

Are you setting proper permissions?

facebookLoginButton.setReadPermissions(Arrays.asList("public_profile", "email"));

plus the way to get the user e-mail is:

String email = (String) user.getProperty("email")

Hope this helps, works as intended in all my apps.

  • i don't want to use the facebook widget button, because it change itself to login/logout.... and i don't need this function: for muy app it must be always login, and so i've done my personal button. any ideas? – D Ferra Jan 27 '15 at 10:57
  • Well you still need to set read permissions in your own button, not entirely sure how you'd go about this though... –  Jan 27 '15 at 11:01
  • beside this problem, i've tried your method and it doesn't work... nullpointer on getProperty – D Ferra Jan 27 '15 at 11:02
  • solved with this: http://stackoverflow.com/questions/17609287/how-to-get-email-id-from-facebook-sdk-in-android-applications – D Ferra Jan 27 '15 at 11:08
0

Solved with this (green V) question: how to get email id from facebook sdk in android applications?

basically:

List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    Session.openActiveSession(this, true,permissions, new Session.StatusCallback() {
Community
  • 1
  • 1
D Ferra
  • 1,223
  • 3
  • 12
  • 21