1

I have a big problem with android-facebook-sdk 3.19.1. No problem to retrieve public information about user but it is not possible getting email address.

I know my post is very near to the following thread ==> facebook android sdk -user email returns null but I have no solution for now.

So here is my code

In my ConnectionActivity.java I have a button R.id.fb_connect

private List<String> permissions = Arrays.asList("email");

@Click(R.id.fb_connect)
protected void fbConnect() {
    ensureOpenSession();
}

private boolean ensureOpenSession() {
    Session session = Session.getActiveSession();
    if (session == null || !session.isOpened()) {
        LOGD(TAG, "Call Session.openActiveSession");
        Session.openActiveSession(this, true, permissions, new FbCallback());
        return false;
    }
    return true;
}

public class FbCallback implements Session.StatusCallback {

    @Override
    public void call(Session session, SessionState sessionState, Exception e) {
        // make request to the /me API
        Request.newMeRequest(session, new Request.GraphUserCallback() {
            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
                if (user != null) {
                    // user.asMap().get("email");
                    Toast.makeText(ConnectionActivity.this, "email : " + user.getProperty("email"), Toast.LENGTH_LONG).show();
                }
            }
        }).executeAsync();
    }
}

I've also tried the code in the link above but it doesn't work. One precision, with this code, I can see the facebook activity which says "XXX will receive the following info: your public profile and email address" but the toast displays "email : null"


EDIT

I work with android studio and my gradle file has the following line

compile 'com.facebook.android:facebook-android-sdk:3.19.1'

EDIT2

If I use

LOGD(TAG, "isPermissionGranted : " + session.isPermissionGranted(permissions.get(0)));

before call Request.newMeRequest so true is shown. Permission is correctly granted

Thx

Community
  • 1
  • 1
mrroboaat
  • 5,602
  • 7
  • 37
  • 65
  • did you got E-mail permission ? – Mina Fawzy Oct 29 '14 at 11:10
  • Yes I received "XXX will receive the following info: your public profile and email address" – mrroboaat Oct 29 '14 at 11:11
  • make sure you got permission with this method isPermissionGranted() – Mina Fawzy Oct 29 '14 at 11:26
  • If I use `LOGD(TAG, "isPermissionGranted : " + session.isPermissionGranted(permissions.get(0)));` so true is shown – mrroboaat Oct 29 '14 at 13:48
  • have a look at this answer http://stackoverflow.com/questions/19797770/facebook-android-sdk-user-email-returns-null – Mina Fawzy Oct 29 '14 at 13:55
  • I know this link and I have tested the code provided by +Ming Li but it doesn't work. email still null, I don't understand ... – mrroboaat Oct 29 '14 at 13:59
  • i work with facebook api and it was fine , but i get just name , please try get name use..getName() to check this code is reachable and have data from fb – Mina Fawzy Oct 29 '14 at 14:02
  • As I mentionned, I can retrieve public informations so `user.getLastName()` and `user.getFirstName()` gives me the right information but `user.getProperty("email")` is null. Do you work with the last fb sdk ? – mrroboaat Oct 29 '14 at 14:04
  • ok then now try this code String Email = user.asMap().get("email").toString(); i hope this work – Mina Fawzy Oct 29 '14 at 14:06
  • Last thing I know , its old method but you may try it String EMail = response.getGraphObject().getProperty("email").toString(); if it dosnt work then i can't help but i hope someone can – Mina Fawzy Oct 29 '14 at 14:14
  • null ! It is just unbelivable. Anyway thanks for your help. I will continue my tests but I'm disappointed. – mrroboaat Oct 29 '14 at 14:23
  • 1
    Facebook API stupid don't bother yourself , when you get answer post it – Mina Fawzy Oct 29 '14 at 14:25
  • Are you testing as yourself? Are you sure the user has an email set in their profile? Two other things you can try: 1.) use the Graph API explorer https://developers.facebook.com/tools/explorer and make a /me request, and see if there's an email field that comes back; 2.) print out the full user.asMap() and see what other fields are coming back. – Ming Li Oct 29 '14 at 21:08
  • Nice this graph api explorer. If I test with my own account, email is not shown whereas my account has an email. If I test with another account, property is returned. Is there a thing to do to "authorize" my email in my account settings ? – mrroboaat Oct 30 '14 at 08:40
  • @aat - have you solved this ? – Heshan Sandeepa Apr 12 '15 at 16:17
  • No. If I get null, i don't show email address – mrroboaat Apr 12 '15 at 16:21
  • @aat have a look at this issue: http://stackoverflow.com/questions/30389180/facebook-oncompleted-email-java-lang-nullpointerexception – Sun May 26 '15 at 12:15

0 Answers0