1

I'm having a problem when I'm trying to get the user's email from Android Facebook SDK. I have set the correct permissions and it works in some cases (I can get all data from user), but sometimes and in some devices, it doesn't work. Also I have disabled the sandbox mode and I have registed my certificate on facebook's site. Please, can anyone help me? Thank you!!!!

private void signInWithFacebook() {

   SessionTracker mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = mSessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(Main.this);


        if (openRequest != null) {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            mCurrentSession.openForRead(openRequest);
        }
    }
    else{
        Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
            public void onCompleted(GraphUser user, Response response) {


                if(!mCurrentSession.getPermissions().contains("email")){

                    id = user.getId();
                    lastname = user.getName();
                    firstname = user.getFirstName();
                    email = user.getProperty("email").toString();
                    image = "http://graph.facebook.com/" + user.getId() + "/picture?type=large";
                    link = user.getLink();
                    ages = user.getBirthday();
                    sex = user.getProperty("gender").toString();

                    new CheckUser().execute();

                }
                else{

                    Toast.makeText(getApplicationContext(), "No email", Toast.LENGTH_LONG).show();




                }



            }
        });
    }


}

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode,
                resultCode, data);

        if (mCurrentSession.isOpened()) {
            Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
                public void onCompleted(GraphUser user, Response response) {

                    id = user.getId();
                    lastname = user.getName();
                    firstname = user.getFirstName();
                    email = user.getProperty("email").toString();
                    image = "http://graph.facebook.com/" + user.getId() + "/picture?type=large";
                    link = user.getLink();
                    ages = user.getBirthday();
                    sex = user.getProperty("gender").toString();


                    new CheckUser().execute();


                }
            });
        } else {
            Session.OpenRequest openRequest = null;
            openRequest = new Session.OpenRequest(Main.this);

            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

            mCurrentSession.openForRead(openRequest);


        }

    }
  • This doesn't answer your question, but please DO NOT use SessionTracker. It's an internal class, and is not part of the public API in the SDK. As such, it's not supported, and can change at any time (which will break your code). There's no reason for your code to use SessionTracker at all. – Ming Li Aug 05 '13 at 21:22
  • Thank you! What should I use instead SessionTracker? – dark_pajuva Aug 06 '13 at 07:18
  • 1
    Nothing, just use Session exclusively. When you need a session, do Session.getActiveSession(), if that's null, then just create a new one by doing Session s = new Session(this); or use the Session.Builder to create a session. – Ming Li Aug 06 '13 at 17:23

0 Answers0