Android Facebook SDK - session.isOpened () always returns false

I (I think) followed Facebook, but I can't get it to work correctly. I try to log in via FB and then get user information. I have:

 private Session.StatusCallback statusCallback = new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            System.out.println("GOOD");
            if (session.isOpened()) {
                System.out.println("AWESOME");
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                  // callback after Graph API response with user object
                  @Override
                  public void onCompleted(GraphUser user, Response response) {
                      m_user = user;
                      System.out.println("Hello " + user.getName());
                  }
                });
            }
        }

And then:

public void onBtnFacebookClick(final View v) {
      Session session = Session.getActiveSession();
      if (session == null) {
          session = new Session(this);
          Session.setActiveSession(session);
          if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
              session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
          }
      }
      if (!session.isOpened() && !session.isClosed()) {
          session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
      } else {
          Session.openActiveSession(this, true, statusCallback);
      }
  }

But it seems that “AWESOME” never prints (“GOOD” prints), although I managed to get into FB. Or maybe I do not understand what it means session.isOpened()?

+5
source share
1 answer

Now it works. I had two problems. One invalid hash key that I corrected after these instructions. Another thing is that I did not know that I had to override this method:

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

All Articles