Android Facebook SDK - session.isOpened()始终返回false

时间:2013-04-28 22:08:54

标签: android facebook

我(我想)跟着Facebook教程,但我无法正常工作。我正在尝试通过FB登录,然后获取有关用户的信息。我有:

 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());
                  }
                });
            }
        }

然后:

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);
      }
  }

但似乎“AWESOME”从未打印过(“GOOD”打印),尽管我设法登录FB。 或者我可能不明白session.isOpened()的含义是什么?

1 个答案:

答案 0 :(得分:9)

好的,现在正在运作。我有两个问题。一个是我在these指令后修复的错误哈希键。 另一个是我不知道我必须覆盖这个方法:

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