Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I (think I) followed Facebook tutorial but I can't get it work properly. I'm trying to login via FB and then get info about the user. 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" is never printed ("GOOD" is printed) eventhough I managed to login to FB. Or maybe I don't understand what session.isOpened() means?

like image 515
Shmoopy Avatar asked Apr 28 '13 22:04

Shmoopy


1 Answers

Ok it's working now. I had two problems. One is incorrect hash key which I fixed following these instructions. The other is that I didn't know 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);
  }
like image 176
Shmoopy Avatar answered Oct 13 '22 01:10

Shmoopy